Skip to content

Commit

Permalink
Documentation and such
Browse files Browse the repository at this point in the history
  • Loading branch information
cetio committed Feb 18, 2024
1 parent 043785d commit 635923c
Show file tree
Hide file tree
Showing 19 changed files with 319 additions and 124 deletions.
5 changes: 3 additions & 2 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
"description": "General-purpose and diverse library intended to expand upon Phobos",
"license": "AGPL-3.0-only",
"name": "tern",
"targetType": "library",
"configurations": [
{
"name": "application"
"name": "application",
"targetType": "executable"
},
{
"name": "library",
"targetType": "library",
"excludedSourceFiles": [
"main.d"
]
Expand Down
11 changes: 6 additions & 5 deletions source/tern/algorithm/package.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// Various general-purpose algorithms and types for working with arrays
module tern.algorithm;

public import tern.algorithm.iteration;
public import tern.algorithm.lazy_filter;
public import tern.algorithm.lazy_map;
public import tern.algorithm.mutation;
public import tern.algorithm.searching;
public import tern.algorithm.iteration; ///
public import tern.algorithm.lazy_filter; ///
public import tern.algorithm.lazy_map; ///
public import tern.algorithm.mutation; ///
public import tern.algorithm.searching; ///
44 changes: 23 additions & 21 deletions source/tern/codegen.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@ public enum exempt;

/**
* Sets `T` as an inherited type, this can be anything, so long as it isn't an intrinsic type.
*
* This is an attribute and should be used like `@inherit!T`
*
* Example:
* ```d
* struct A {int b; int x() => b; }
* Example:
* ```d
* struct A {int b; int x() => b; }
*
* interface B { string y(); }
* interface B { string y(); }
*
* @inherit!A @inherit!B struct C
* {
* mixin apply;
* @inherit!A @inherit!B struct C
* {
* mixin apply;
*
* string y() => "yohoho!";
* }
* ```
* string y() => "yohoho!";
* }
* ```
*/
public template inherit(T)
if (hasChildren!T)
Expand All @@ -38,22 +39,23 @@ public template inherit(T)
}

/**
* Sets up all inherits for the type that mixes this in.
* Sets up all inherits for the type that mixes this in.
*
* Must set inherited types by using `inherit(T)` beforehand.
*
* Example:
* ```d
* struct A {int b; int x() => b; }
* Example:
* ```d
* struct A {int b; int x() => b; }
*
* interface B { string y(); }
* interface B { string y(); }
*
* @inherit!A @inherit!B struct C
* {
* mixin applyInherits;
* @inherit!A @inherit!B struct C
* {
* mixin apply;
*
* string y() => "yohoho!";
* }
* ```
* string y() => "yohoho!";
* }
* ```
*/
// TODO: Use opDispatch to allow for multiple class/struct inherits
// Find a faster way to do this, do not regenerate every call
Expand Down
16 changes: 8 additions & 8 deletions source/tern/digest/cipher.d
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/// Implements all encrypting digests
module tern.digest.cipher;

public import tern.digest.chacha20;
public import tern.digest.mira;
public import tern.digest.rc4;
public import tern.digest.salsa20;
public import tern.digest.anura;
public import tern.digest.tea;
public import tern.digest.hight;
public import tern.digest.gimli;
public import tern.digest.chacha20; ///
public import tern.digest.mira; ///
public import tern.digest.rc4; ///
public import tern.digest.salsa20; ///
public import tern.digest.anura; ///
public import tern.digest.tea; ///
public import tern.digest.hight; ///
public import tern.digest.gimli; ///
28 changes: 14 additions & 14 deletions source/tern/digest/hash.d
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/// Implements all hashing digests
module tern.digest.hash;

public import tern.digest.adler32;
public import tern.digest.berus;
public import tern.digest.crc32;
public import tern.digest.circe;
public import tern.digest.fnv1;
public import tern.digest.md5;
public import tern.digest.murmurhash;
public import tern.digest.sha;
public import tern.digest.superfasthash;
public import tern.digest.xxhash;
public import tern.digest.cityhash;
public import tern.digest.djb2;
public import tern.digest.elfhash;
public import tern.digest.ripemd;
public import tern.digest.adler32; ///
public import tern.digest.berus; ///
public import tern.digest.crc32; ///
public import tern.digest.circe; ///
public import tern.digest.fnv1; ///
public import tern.digest.md5; ///
public import tern.digest.murmurhash; ///
public import tern.digest.sha; ///
public import tern.digest.superfasthash; ///
public import tern.digest.xxhash; ///
public import tern.digest.cityhash; ///
public import tern.digest.djb2; ///
public import tern.digest.elfhash; ///
public import tern.digest.ripemd; ///
4 changes: 4 additions & 0 deletions source/tern/digest/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import tern.traits;
import tern.object;
import tern.meta;

/// Attribute for marking a class as a digester, must implement `encrypt` or `hash `
public enum digester;

/// True if `T` is a digester of any kind.
public alias isDigest(T) = Alias!(seqContains!(digester, __traits(getAttributes, T)));
/// True if `T` is an encrypting digester.
public alias isEncryptingDigest(T) = Alias!(isDigest!T && hasStaticMember!(T, "encrypt"));
/// True if `T` is an hashing digester.
public alias isHashingDigest(T) = Alias!(isDigest!T && hasStaticMember!(T, "hash"));

/* public class Digest(T, IV...)
Expand Down
121 changes: 121 additions & 0 deletions source/tern/digest/sha.d
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
/// Implementation of SHA digesters
module tern.digest.sha;

import tern.digest;

/**
* Implementation of Secure Hash Algorithm (SHA) digester.
*
* SHA is a family of cryptographic hash functions used to generate a fixed-size hash value from
* input data of variable length. The SHA family includes variants such as SHA-1, SHA-256, SHA-512,
* SHA-224, and SHA-384, each with different bit lengths.
*
* Example:
* ```d
* import tern.digest.sha;
*
* ubyte[] data = [1, 2, 3, 4, 5];
* auto sha1Hash = SHA1.hash(data);
* ```
*/
public static @digester class SHA1
{
public:
static:
pure:
/**
* Computes the SHA-1 hash of the given byte array `data`.
*
* Params:
* data = Input byte array to compute the hash.
*
* Returns:
* SHA-1 hash value as a byte array.
*/
auto hash(ubyte[] data)
{
import std.digest;
Expand All @@ -15,11 +40,35 @@ pure:
}
}

/**
* Implementation of Secure Hash Algorithm (SHA) digester.
*
* SHA is a family of cryptographic hash functions used to generate a fixed-size hash value from
* input data of variable length. The SHA family includes variants such as SHA-1, SHA-256, SHA-512,
* SHA-224, and SHA-384, each with different bit lengths.
*
* Example:
* ```d
* import tern.digest.sha;
*
* ubyte[] data = [1, 2, 3, 4, 5];
* auto sha256Hash = SHA256.hash(data);
* ```
*/
public static @digester class SHA256
{
public:
static:
pure:
/**
* Computes the SHA-256 hash of the given byte array `data`.
*
* Params:
* data = Input byte array to compute the hash.
*
* Returns:
* SHA-256 hash value as a byte array.
*/
auto hash(ubyte[] data)
{
import std.digest;
Expand All @@ -28,11 +77,35 @@ pure:
}
}

/**
* Implementation of Secure Hash Algorithm (SHA) digester.
*
* SHA is a family of cryptographic hash functions used to generate a fixed-size hash value from
* input data of variable length. The SHA family includes variants such as SHA-1, SHA-256, SHA-512,
* SHA-224, and SHA-384, each with different bit lengths.
*
* Example:
* ```d
* import tern.digest.sha;
*
* ubyte[] data = [1, 2, 3, 4, 5];
* auto sha512Hash = SHA512.hash(data);
* ```
*/
public static @digester class SHA512
{
public:
static:
pure:
/**
* Computes the SHA-512 hash of the given byte array `data`.
*
* Params:
* data = Input byte array to compute the hash.
*
* Returns:
* SHA-512 hash value as a byte array.
*/
auto hash(ubyte[] data)
{
import std.digest;
Expand All @@ -41,11 +114,35 @@ pure:
}
}

/**
* Implementation of Secure Hash Algorithm (SHA) digester.
*
* SHA is a family of cryptographic hash functions used to generate a fixed-size hash value from
* input data of variable length. The SHA family includes variants such as SHA-1, SHA-256, SHA-512,
* SHA-224, and SHA-384, each with different bit lengths.
*
* Example:
* ```d
* import tern.digest.sha;
*
* ubyte[] data = [1, 2, 3, 4, 5];
* auto sha224Hash = SHA224.hash(data);
* ```
*/
public static @digester class SHA224
{
public:
static:
pure:
/**
* Computes the SHA-224 hash of the given byte array `data`.
*
* Params:
* data = Input byte array to compute the hash.
*
* Returns:
* SHA-224 hash value as a byte array.
*/
auto hash(ubyte[] data)
{
import std.digest;
Expand All @@ -54,11 +151,35 @@ pure:
}
}

/**
* Implementation of Secure Hash Algorithm (SHA) digester.
*
* SHA is a family of cryptographic hash functions used to generate a fixed-size hash value from
* input data of variable length. The SHA family includes variants such as SHA-1, SHA-256, SHA-512,
* SHA-224, and SHA-384, each with different bit lengths.
*
* Example:
* ```d
* import tern.digest.sha;
*
* ubyte[] data = [1, 2, 3, 4, 5];
* auto sha384Hash = SHA384.hash(data);
* ```
*/
public static @digester class SHA384
{
public:
static:
pure:
/**
* Computes the SHA-384 hash of the given byte array `data`.
*
* Params:
* data = Input byte array to compute the hash.
*
* Returns:
* SHA-384 hash value as a byte array.
*/
auto hash(ubyte[] data)
{
import std.digest;
Expand Down
Loading

0 comments on commit 635923c

Please sign in to comment.