# HG changeset patch # User Thomas Dixon # Date 1242180573 14400 # Node ID 2b4bccdc8387f5763d85e29b692ae9dc0346f4f9 # Parent f429c5e9dd697d8d1942ca642978013720e26ee0 Added version() statements to play nice with D2's current feelings about const. Changed a few methods (addEntropy and read in the base PRNG class, and the constructor for ParametersWithIV) to accept void[] in place of ubyte[]. diff -r f429c5e9dd69 -r 2b4bccdc8387 dcrypt/crypto/BlockCipherPadding.d --- a/dcrypt/crypto/BlockCipherPadding.d Tue May 12 17:10:47 2009 -0400 +++ b/dcrypt/crypto/BlockCipherPadding.d Tue May 12 22:09:33 2009 -0400 @@ -13,29 +13,38 @@ /** Base padding class for implementing block padding schemes. */ abstract class BlockCipherPadding { - /** Returns: The name of the padding scheme implemented. */ - string name(); - - /** - * Generate padding to a specific length. - * - * Params: - * len = Length of padding to generate - * - * Returns: The padding bytes to be added. - */ - ubyte[] pad(uint len); + /** Returns: The name of the padding scheme implemented. */ + string name(); + + /** + * Generate padding to a specific length. + * + * Params: + * len = Length of padding to generate + * + * Returns: The padding bytes to be added. + */ + ubyte[] pad(uint len); + + /** + * Return the number of pad bytes in the block. + * + * Params: + * input_ = Padded block of which to count the pad bytes. + * + * Returns: The number of pad bytes in the block. + * + * Throws: dcrypt.crypto.errors.InvalidPaddingError if + * pad length cannot be discerned. + */ + uint unpad(void[] input_); - /** - * Return the number of pad bytes in the block. - * - * Params: - * input_ = Padded block of which to count the pad bytes. - * - * Returns: The number of pad bytes in the block. - * - * Throws: dcrypt.crypto.errors.InvalidPaddingError if - * pad length cannot be discerned. - */ - uint unpad(void[] input_); + /** Play nice with D2's idea of const. */ + version (D_Version2) + { + uint unpad(string input_) + { + return unpad(cast(ubyte[])input_); + } + } } diff -r f429c5e9dd69 -r 2b4bccdc8387 dcrypt/crypto/Cipher.d --- a/dcrypt/crypto/Cipher.d Tue May 12 17:10:47 2009 -0400 +++ b/dcrypt/crypto/Cipher.d Tue May 12 22:09:33 2009 -0400 @@ -45,6 +45,15 @@ */ uint update(void[] input_, void[] output_); + /** Play nice with D2's idea of const. */ + version (D_Version2) + { + uint update(string input_, void[] output_) + { + return update(cast(ubyte[])input_, output_); + } + } + /** Returns: The name of the algorithm of this cipher. */ string name(); diff -r f429c5e9dd69 -r 2b4bccdc8387 dcrypt/crypto/Hash.d --- a/dcrypt/crypto/Hash.d Tue May 12 17:10:47 2009 -0400 +++ b/dcrypt/crypto/Hash.d Tue May 12 22:09:33 2009 -0400 @@ -36,6 +36,15 @@ update(input); } + /** Play nice with D2's idea of const. */ + version (D_Version2) + { + this (string input_) + { + return this(cast(ubyte[])input_); + } + } + /** Returns: The block size of the hash function in bytes. */ abstract uint blockSize(); @@ -85,6 +94,15 @@ return this; } + /** Play nice with D2's idea of const. */ + version (D_Version2) + { + Hash update(string input_) + { + return update(cast(ubyte[])input_); + } + } + /** Hash function's internal transformation. */ protected abstract void transform(ubyte[] input); diff -r f429c5e9dd69 -r 2b4bccdc8387 dcrypt/crypto/MAC.d --- a/dcrypt/crypto/MAC.d Tue May 12 17:10:47 2009 -0400 +++ b/dcrypt/crypto/MAC.d Tue May 12 22:09:33 2009 -0400 @@ -32,6 +32,15 @@ */ void update(void[] input_); + /** Play nice with D2's idea of const. */ + version (D_Version2) + { + void update(string input_) + { + update(cast(ubyte[])input_); + } + } + /** Returns: The name of this MAC. */ string name(); diff -r f429c5e9dd69 -r 2b4bccdc8387 dcrypt/crypto/PRNG.d --- a/dcrypt/crypto/PRNG.d Tue May 12 17:10:47 2009 -0400 +++ b/dcrypt/crypto/PRNG.d Tue May 12 22:09:33 2009 -0400 @@ -32,7 +32,16 @@ * Params: * input = Bytes to introduce into the PRNG as entropy */ - void addEntropy(ubyte[] input); + void addEntropy(void[] input); + + /** Play nice with D2's idea of const. */ + version (D_Version2) + { + void addEntropy(string input) + { + addEntropy(cast(ubyte[])input); + } + } /** * Read bytes from the keystream of the PRNG into output. @@ -40,7 +49,7 @@ * Params: * output = Array to fill with the next bytes of the keystream */ - uint read(ubyte[] output); + uint read(void[] output_); /** Returns: The name of the PRNG algorithm */ string name(); diff -r f429c5e9dd69 -r 2b4bccdc8387 dcrypt/crypto/params/ParametersWithIV.d --- a/dcrypt/crypto/params/ParametersWithIV.d Tue May 12 17:10:47 2009 -0400 +++ b/dcrypt/crypto/params/ParametersWithIV.d Tue May 12 22:09:33 2009 -0400 @@ -21,7 +21,7 @@ * params = Parameters to wrap. * iv = IV to be held. */ - this (CipherParameters params=null, ubyte[] iv=null) + this (CipherParameters params=null, void[] iv=null) { _params = params; _iv = cast(ubyte[]) iv; diff -r f429c5e9dd69 -r 2b4bccdc8387 dcrypt/crypto/prngs/PBKDF2.d --- a/dcrypt/crypto/prngs/PBKDF2.d Tue May 12 17:10:47 2009 -0400 +++ b/dcrypt/crypto/prngs/PBKDF2.d Tue May 12 22:09:33 2009 -0400 @@ -69,16 +69,18 @@ _initialized = true; } - void addEntropy(ubyte[] input) + void addEntropy(void[] input) { - throw new NotSupportedError(name()~": Not supported."); + throw new NotSupportedError(name()~": addEntropy is not supported."); } /** * Throws: LimitReachedError after 2^32 blocks. */ - uint read(ubyte[] output) + uint read(void[] output_) { + ubyte[] output = cast(ubyte[])output_; + for (uint i = 0; i < output.length; i++) { if (index == buffer.length) diff -r f429c5e9dd69 -r 2b4bccdc8387 dcrypt/crypto/prngs/PRNGFromHash.d --- a/dcrypt/crypto/prngs/PRNGFromHash.d Tue May 12 17:10:47 2009 -0400 +++ b/dcrypt/crypto/prngs/PRNGFromHash.d Tue May 12 22:09:33 2009 -0400 @@ -28,7 +28,7 @@ string name() { if (hash is null) - throw new NotInitializedError(name()~": PRNG not initialized"); + throw new NotInitializedError(name()~": PRNG not initialized."); return hash.name~"PRNG"; } @@ -49,7 +49,7 @@ index = this.hash.digestSize; // to force updating of the state } - void addEntropy(ubyte[] input) + void addEntropy(void[] input) { if (!_initialized) { @@ -57,13 +57,15 @@ seed = hash.digest(); _initialized = true; } else - throw new NotSupportedError(name()~": state is immutable once initialized"); + throw new NotSupportedError(name()~": state is immutable once initialized."); } - uint read(ubyte[] output) + uint read(void[] output_) { if (!_initialized) - throw new NotInitializedError(name()~": PRNG not initialized"); + throw new NotInitializedError(name()~": PRNG not initialized."); + + ubyte[] output = cast(ubyte[])output_; for (uint i = 0; i < output.length; i++) { diff -r f429c5e9dd69 -r 2b4bccdc8387 dcrypt/misc/ByteConverter.d --- a/dcrypt/misc/ByteConverter.d Tue May 12 17:10:47 2009 -0400 +++ b/dcrypt/misc/ByteConverter.d Tue May 12 22:09:33 2009 -0400 @@ -165,6 +165,15 @@ return cast(string)output; } + /** Play nice with D2's idea of const. */ + version (D_Version2) + { + static string hexEncode(string input_) + { + return hexEncode(cast(ubyte[])input_); + } + } + static ubyte[] hexDecode(string input) { string inputAsLower = stringToLower(input); diff -r f429c5e9dd69 -r 2b4bccdc8387 dcrypt/misc/Checksum.d --- a/dcrypt/misc/Checksum.d Tue May 12 17:10:47 2009 -0400 +++ b/dcrypt/misc/Checksum.d Tue May 12 22:09:33 2009 -0400 @@ -22,6 +22,15 @@ */ uint compute(void[] input_, uint start); + /** Play nice with D2's idea of const. */ + version (D_Version2) + { + uint compute(string input_, uint start) + { + return compute(cast(ubyte[])input_, start); + } + } + /** Returns: The name of the checksum algorithm. */ string name(); }