diff --git a/CHANGELOG.md b/CHANGELOG.md index e61625e..cbd26c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## v0.5.0 +API Break changes see details below: +- Renamed HexCoder to Base16Encoder to align with Base32, Bech32 implementations +- Rename Bech32Coder to Bech32Encoder for similar reasons above. +- Added decodeNoHrpCheck static fucntion to Bech32Encoder for being able to decode and alreay encoded bech32 string. +- Made internal Bech32 classes private. +- Removed unnecessary fromList constructors, as ByteList based default constructors require Iterable +- Added + - ByteList.withConstraint: Create a ByteList wit min, max length set to constraint specified + - ByteList.decodeWithConstraint: Same as above but from (base16, bech32 etc) encoded strings. + - ByteList.withConstraintRange: Create a ByteList within the min, max length range i.e., + the created ByteList mist be in the range. + - ByteList.decodeWithConstraintRange: Same as above but from (base16, bech32 etc) encoded strings. +- Refactored the code based on these above changes. ## v0.4.2 Added bytes length for decoding ByteList diff --git a/README.md b/README.md index 01d3c88..8f59fae 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Thes library has the aim of 1. Add the following into the `pubspec.yaml` of your dart package: ``` yaml dependencies: - pinenacl: ^0.4.1 + pinenacl: ^0.5.0 ``` 2. You can install now from the command line with pub: diff --git a/example/hashing.dart b/example/hashing.dart index 176c23d..a809ac3 100644 --- a/example/hashing.dart +++ b/example/hashing.dart @@ -3,7 +3,7 @@ import 'package:pinenacl/src/digests/digests.dart'; import 'package:pinenacl/tweetnacl.dart'; void main() { - const hex = HexCoder.instance; + const hex = Base16Encoder.instance; print('\n### Hashing - Blake2b Example ###\n'); diff --git a/example/signature.dart b/example/signature.dart index abda0e5..eac07b6 100644 --- a/example/signature.dart +++ b/example/signature.dart @@ -1,7 +1,7 @@ import 'package:pinenacl/ed25519.dart'; void main() { - const hex = HexCoder.instance; + const hex = Base16Encoder.instance; print('\n### Digital Signatures - Signing Example ###\n'); /// Signer’s perspective (SigningKey) diff --git a/lib/api/api.dart b/lib/api/api.dart index adbf1d0..7b63940 100644 --- a/lib/api/api.dart +++ b/lib/api/api.dart @@ -3,35 +3,76 @@ part of pinenacl.api; abstract class AsymmetricKey extends ByteList with Encodable { - AsymmetricKey(Uint8List data, [int? keyLength]) : super(data, keyLength); - AsymmetricKey.fromList(Uint8List data) : super.fromList(data); + AsymmetricKey(Uint8List bytes, {required int keyLength}) + : super.withConstraint(bytes, constraintLength: keyLength); AsymmetricPublicKey get publicKey; } abstract class AsymmetricPublicKey extends AsymmetricKey { - AsymmetricPublicKey(Uint8List data, [int? bytesLength]) - : super(data, bytesLength); - AsymmetricPublicKey.fromList(Uint8List data) : super.fromList(data); + AsymmetricPublicKey(Uint8List bytes, {required int keyLength}) + : super(bytes, keyLength: keyLength); } abstract class AsymmetricPrivateKey extends AsymmetricKey { - AsymmetricPrivateKey(Uint8List data, [int? keyLength]) - : super(data, keyLength); + AsymmetricPrivateKey(Uint8List bytes, {required int keyLength}) + : super(bytes, keyLength: keyLength); } +/// /// `ByteList` is the base of the PineNaCl cryptographic library, /// which is based on the unmodifiable Uin8List class +/// The bytelist can be created either from +/// - hex string (with or without '0x' prefix) or +/// - List of int's +/// +/// ByteList can have a `min` and `max` length specified. +/// - `minLength` means the length of the constructable ByteList must be equal +/// of bigger. +/// - `maxLength` means the ByteList length must be less (till `minLength`) or +/// equal. +/// +/// Theses two options can be used for creating a class with fixed-length ByteList or +/// a class which has some constraints e.g., a class that can only create a ByteList +/// that is longer or equal than 16 and shorter or equal than 32. +/// class ByteList with ListMixin, Encodable { - ByteList(Iterable bytes, [int? bytesLength]) - : _u8l = _constructList( - bytes, bytesLength ?? bytes.length, bytesLength ?? bytes.length); - - ByteList.fromList(Uint8List list, - [int minLength = _minLength, int maxLength = _maxLength]) - : _u8l = _constructList(list, minLength, maxLength); - - ByteList.decode(String data, {Encoder defaultDecoder = decoder, int? bytesLength}) - : this(defaultDecoder.decode(data), bytesLength); + /// It creates an data's length ByteList + ByteList(Iterable data) + : _u8l = _constructList(data, data.length, data.length); + + /// It creates a ByteList and checks wheter the data's length is equal with + /// the specified constraint (min and max length equal). + + ByteList.withConstraint(Iterable data, {required int constraintLength}) + : _u8l = _constructList(data, constraintLength, constraintLength); + + /// It creates a ByteList and checks wheter the data's length is equal with + /// the specified constraints (allowed range i.e., min and max length) + /// + /// e.g. data.length >= min and data.length <= max. + ByteList.withConstraintRange(Iterable data, + {int min = _minLength, int max = _maxLength}) + : _u8l = _constructList(data, min, max); + + /// Decoding encoded String to a ByteList. There is no size constraints for the + /// decoded bytes. + /// TODO: create unit tests for decoding constructors. + ByteList.decode(String encodedString, {Encoder coder = decoder}) + : this(coder.decode(encodedString)); + + /// Decoding encoded string to a ByteList with the expected length of the + /// encoded bytes. + ByteList.decodeWithConstraint(String encodedString, + {Encoder coder = decoder, required int constraintLength}) + : this.withConstraint(coder.decode(encodedString), + constraintLength: constraintLength); + + /// Decoding encoded string to a ByteList with the expected min and max lengths of the + /// encoded bytes. + ByteList.decodeWithConstraintRange(String encodedString, + {Encoder coder = decoder, int min = _minLength, int max = _maxLength}) + : this.withConstraintRange(coder.decode(encodedString), + min: min, max: max); static const _minLength = 0; @@ -41,16 +82,16 @@ class ByteList with ListMixin, Encodable { final Uint8List _u8l; static Uint8List _constructList( - Iterable list, int minLength, int maxLength) { - if (list.length < minLength || list.length > maxLength) { + Iterable data, int minLength, int maxLength) { + if (data.length < minLength || data.length > maxLength) { throw Exception( - 'The list length (${list.length}) is invalid (min: $minLength, max: $maxLength)'); + 'The list length (${data.length}) is invalid (min: $minLength, max: $maxLength)'); } - return UnmodifiableUint8ListView(Uint8List.fromList(list.toList())); + return UnmodifiableUint8ListView(Uint8List.fromList(data.toList())); } // Default encoder/decoder is the HexCoder() - static const decoder = HexCoder.instance; + static const decoder = Base16Encoder.instance; @override Encoder get encoder => decoder; @@ -88,14 +129,16 @@ class ByteList with ListMixin, Encodable { @override ByteList sublist(int start, [int? end]) { final sublist = _u8l.sublist(start, end ?? _u8l.length); - return ByteList(sublist, sublist.length); + return ByteList.withConstraint(sublist, constraintLength: sublist.length); } } mixin Suffix on ByteList { int get prefixLength; - ByteList get prefix => ByteList(take(prefixLength), prefixLength); - ByteList get suffix => ByteList(skip(prefixLength), length - prefixLength); + ByteList get prefix => ByteList.withConstraint(take(prefixLength), + constraintLength: prefixLength); + ByteList get suffix => ByteList.withConstraint(skip(prefixLength), + constraintLength: length - prefixLength); } extension ByteListExtension on ByteList { diff --git a/lib/api/authenticated_encryption.dart b/lib/api/authenticated_encryption.dart index 6dc0c65..4da3234 100644 --- a/lib/api/authenticated_encryption.dart +++ b/lib/api/authenticated_encryption.dart @@ -6,7 +6,7 @@ typedef Crypting = Uint8List Function( Uint8List out, Uint8List text, int textLen, Uint8List nonce, Uint8List k); abstract class BoxBase extends ByteList { - BoxBase.fromList(Uint8List list) : super.fromList(list); + BoxBase.fromList(Uint8List list) : super(list); late Crypting doEncrypt; late Crypting doDecrypt; @@ -46,10 +46,11 @@ abstract class BoxBase extends ByteList { class EncryptedMessage extends ByteList with Suffix { EncryptedMessage({required Uint8List nonce, required Uint8List cipherText}) - : super.fromList((nonce + cipherText).toUint8List(), nonceLength, - nonce.length + cipherText.length); + : super.withConstraintRange((nonce + cipherText).toUint8List(), + min: nonceLength, max: nonce.length + cipherText.length); - EncryptedMessage.fromList(Uint8List list) : super.fromList(list, nonceLength); + EncryptedMessage.fromList(Uint8List bytes) + : super.withConstraintRange(bytes, min: nonceLength); static const nonceLength = 24; @@ -61,12 +62,12 @@ class EncryptedMessage extends ByteList with Suffix { } class PublicKey extends AsymmetricPublicKey { - PublicKey(Uint8List bytes) : super(bytes, keyLength); + PublicKey(Uint8List bytes) : super(bytes, keyLength: keyLength); PublicKey.decode(String keyString, [Encoder coder = decoder]) : this(coder.decode(keyString)); - static const decoder = Bech32Coder(hrp: 'x25519_pk'); + static const decoder = Bech32Encoder(hrp: 'x25519_pk'); @override PublicKey get publicKey => this; @@ -84,7 +85,7 @@ class PublicKey extends AsymmetricPublicKey { /// ECDH /// class PrivateKey extends AsymmetricPrivateKey { - PrivateKey(Uint8List secret) : super(secret, keyLength); + PrivateKey(Uint8List secret) : super(secret, keyLength: keyLength); PrivateKey.fromSeed(Uint8List seed) : this(_seedToHash(seed)); @@ -93,7 +94,7 @@ class PrivateKey extends AsymmetricPrivateKey { PrivateKey.decode(String keyString, [Encoder coder = decoder]) : this(coder.decode(keyString)); - static const decoder = Bech32Coder(hrp: 'x25519_sk'); + static const decoder = Bech32Encoder(hrp: 'x25519_sk'); static const seedSize = TweetNaCl.seedSize; static const keyLength = TweetNaCl.secretKeyLength; diff --git a/lib/api/encoding.dart b/lib/api/encoding.dart index b786398..2fa2891 100644 --- a/lib/api/encoding.dart +++ b/lib/api/encoding.dart @@ -1,5 +1,7 @@ part of pinenacl.api; +/// The Encoder interface for classes that are capable for encoding data, +/// therefore they need decoding function too. abstract class Encoder { String encode(ByteList data); Uint8List decode(String data); diff --git a/lib/encoding.dart b/lib/encoding.dart index 4bbf6bc..a85682e 100644 --- a/lib/encoding.dart +++ b/lib/encoding.dart @@ -8,4 +8,4 @@ import 'package:pinenacl/api.dart'; part 'src/encoding/base32_encoder.dart'; part 'src/encoding/bech32_encoder.dart'; -part 'src/encoding/hex_encoder.dart'; +part 'src/encoding/base16_encoder.dart'; diff --git a/lib/src/authenticated_encryption/public.dart b/lib/src/authenticated_encryption/public.dart index d0e1406..8c60517 100644 --- a/lib/src/authenticated_encryption/public.dart +++ b/lib/src/authenticated_encryption/public.dart @@ -54,7 +54,7 @@ class Box extends BoxBase { ByteList get sharedKey => this; - static const decoder = HexCoder.instance; + static const decoder = Base16Encoder.instance; @override Encoder get encoder => decoder; @@ -113,7 +113,7 @@ class SealedBox extends ByteList { SealedBox._fromKeyPair( AsymmetricPrivateKey? privateKey, AsymmetricPublicKey publicKey) : _privateKey = privateKey, - super.fromList(publicKey.asTypedList); + super(publicKey); factory SealedBox(AsymmetricKey key) { if (key is AsymmetricPrivateKey) { @@ -136,7 +136,7 @@ class SealedBox extends ByteList { static const _macBytes = TweetNaCl.macBytes; static const _sealBytes = _pubLength + _macBytes; - static const decoder = HexCoder.instance; + static const decoder = Base16Encoder.instance; @override Encoder get encoder => decoder; diff --git a/lib/src/authenticated_encryption/secret.dart b/lib/src/authenticated_encryption/secret.dart index 29e370a..97f06f7 100644 --- a/lib/src/authenticated_encryption/secret.dart +++ b/lib/src/authenticated_encryption/secret.dart @@ -43,7 +43,7 @@ class SecretBox extends BoxBase { static const keyLength = TweetNaCl.keyLength; static const macBytes = TweetNaCl.macBytes; - static const decoder = HexCoder.instance; + static const decoder = Base16Encoder.instance; @override Encoder get encoder => decoder; diff --git a/lib/src/encoding/hex_encoder.dart b/lib/src/encoding/base16_encoder.dart similarity index 92% rename from lib/src/encoding/hex_encoder.dart rename to lib/src/encoding/base16_encoder.dart index 07051df..244b427 100644 --- a/lib/src/encoding/hex_encoder.dart +++ b/lib/src/encoding/base16_encoder.dart @@ -1,8 +1,8 @@ part of pinenacl.encoding; -class HexCoder implements Encoder { - const HexCoder._singleton(); - static const HexCoder instance = HexCoder._singleton(); +class Base16Encoder implements Encoder { + const Base16Encoder._singleton(); + static const Base16Encoder instance = Base16Encoder._singleton(); static const _alphabet = '0123456789abcdef'; static const _hexMap = { diff --git a/lib/src/encoding/bech32_encoder.dart b/lib/src/encoding/bech32_encoder.dart index 5ebaab5..e247006 100644 --- a/lib/src/encoding/bech32_encoder.dart +++ b/lib/src/encoding/bech32_encoder.dart @@ -1,7 +1,7 @@ part of pinenacl.encoding; -class Bech32Coder implements Encoder { - const Bech32Coder({required this.hrp}); +class Bech32Encoder implements Encoder { + const Bech32Encoder({required this.hrp}); final String hrp; static const maxHrpLength = 83; @@ -12,18 +12,24 @@ class Bech32Coder implements Encoder { @override String encode(List data) { var be = Base32Encoder._convertBits(data, 8, 5, true); - return Bech32Codec().encode(Bech32(hrp, be), maxLength); + return _Bech32Codec().encode(_Bech32(hrp, be), maxLength); } @override Uint8List decode(String data) { - final be32 = Bech32Codec().decode(data, maxLength); + final be32 = _Bech32Codec().decode(data, maxLength); if (be32.hrp != hrp) { throw Exception('Invalid `hrp`. Expected $hrp got ${be32.hrp}'); } return Uint8List.fromList( Base32Encoder._convertBits(be32.data, 5, 8, false)); } + + static Uint8List decodeNoHrpCheck(String data, int maxLenght) { + final be32 = _Bech32Codec().decode(data, maxLength); + return Uint8List.fromList( + Base32Encoder._convertBits(be32.data, 5, 8, false)); + } } // ignore: slash_for_doc_comments @@ -51,40 +57,40 @@ class Bech32Coder implements Encoder { * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ -class Bech32 { - Bech32(this.hrp, this.data); +class _Bech32 { + _Bech32(this.hrp, this.data); final String hrp; final List data; } -const Bech32Codec bech32 = Bech32Codec(); +//const _Bech32Codec bech32 = _Bech32Codec(); -class Bech32Codec extends Codec { - const Bech32Codec(); +class _Bech32Codec extends Codec<_Bech32, String> { + const _Bech32Codec(); @override - Bech32Decoder get decoder => Bech32Decoder(); + _Bech32Decoder get decoder => _Bech32Decoder(); @override - Bech32Encoder get encoder => Bech32Encoder(); + _Bech32Encoder get encoder => _Bech32Encoder(); @override - String encode(Bech32 input, + String encode(_Bech32 input, [int maxLength = Bech32Validations.maxInputLength]) { - return Bech32Encoder().convert(input, maxLength); + return _Bech32Encoder().convert(input, maxLength); } @override - Bech32 decode(String encoded, + _Bech32 decode(String encoded, [int maxLength = Bech32Validations.maxInputLength]) { - return Bech32Decoder().convert(encoded, maxLength); + return _Bech32Decoder().convert(encoded, maxLength); } } // This class converts a Bech32 class instance to a String. -class Bech32Encoder extends Converter with Bech32Validations { +class _Bech32Encoder extends Converter<_Bech32, String> with Bech32Validations { @override - String convert(Bech32 input, + String convert(_Bech32 input, [int maxLength = Bech32Validations.maxInputLength]) { var hrp = input.hrp; var data = input.data; @@ -124,9 +130,9 @@ class Bech32Encoder extends Converter with Bech32Validations { } // This class converts a String to a Bech32 class instance. -class Bech32Decoder extends Converter with Bech32Validations { +class _Bech32Decoder extends Converter with Bech32Validations { @override - Bech32 convert(String input, + _Bech32 convert(String input, [int maxLength = Bech32Validations.maxInputLength]) { if (input.length > maxLength) { throw TooLong(input.length); @@ -182,7 +188,7 @@ class Bech32Decoder extends Converter with Bech32Validations { throw InvalidChecksum(); } - return Bech32(hrp, dataBytes); + return _Bech32(hrp, dataBytes); } } @@ -224,38 +230,14 @@ class Bech32Validations { const String separator = '1'; const List charset = [ - 'q', - 'p', - 'z', - 'r', - 'y', - '9', - 'x', - '8', - 'g', - 'f', - '2', - 't', - 'v', - 'd', - 'w', - '0', - 's', - '3', - 'j', - 'n', - '5', - '4', - 'k', - 'h', - 'c', - 'e', - '6', - 'm', - 'u', - 'a', - '7', - 'l', + 'q', 'p', 'z', 'r', // Bech32 charset + 'y', '9', 'x', '8', + 'g', 'f', '2', 't', + 'v', 'd', 'w', '0', + 's', '3', 'j', 'n', + '5', '4', 'k', 'h', + 'c', 'e', '6', 'm', + 'u', 'a', '7', 'l', ]; const List generator = [ diff --git a/lib/src/message_authentication/hmac.dart b/lib/src/message_authentication/hmac.dart index 2155ef5..49e4933 100644 --- a/lib/src/message_authentication/hmac.dart +++ b/lib/src/message_authentication/hmac.dart @@ -4,7 +4,7 @@ import 'package:pinenacl/tweetnacl.dart'; void main() { final key = List.generate(20, (index) => 0xb).toUint8List(); final data = Uint8List.fromList('Hi There'.codeUnits); - final hex = HexCoder.instance; + final hex = Base16Encoder.instance; // Test case 1 fro https://www.rfc-editor.org/rfc/rfc4231.txt /*final hmac_sha_224 = diff --git a/lib/src/signatures/ed25519.dart b/lib/src/signatures/ed25519.dart index 082b69a..a5e8525 100644 --- a/lib/src/signatures/ed25519.dart +++ b/lib/src/signatures/ed25519.dart @@ -3,19 +3,21 @@ import 'package:pinenacl/api/signatures.dart'; import 'package:pinenacl/src/tweetnacl/tweetnacl.dart'; class Signature extends ByteList implements SignatureBase { - Signature(Uint8List bytes) : super(bytes, signatureLength); + Signature(Uint8List bytes) + : super.withConstraint(bytes, constraintLength: signatureLength); static const signatureLength = TweetNaCl.signatureLength; } class VerifyKey extends AsymmetricPublicKey implements Verify { - VerifyKey(Uint8List bytes, [int keyLength = keyLength]) - : super(bytes, keyLength); - VerifyKey.decode(String keyString, {Encoder coder = decoder}) - : this(coder.decode(keyString), coder.decode(keyString).length); + VerifyKey(Uint8List bytes, {int keyLength = keyLength}) + : super(bytes, keyLength: keyLength); + VerifyKey.decode(String keyString, + {Encoder coder = decoder, int keyLength = keyLength}) + : this(coder.decode(keyString), keyLength: keyLength); static const keyLength = TweetNaCl.publicKeyLength; - static const decoder = Bech32Coder(hrp: 'ed25519_pk'); + static const decoder = Bech32Encoder(hrp: 'ed25519_pk'); @override VerifyKey get publicKey => this; @@ -75,7 +77,7 @@ class SigningKey extends AsymmetricPrivateKey with Suffix implements Sign { SigningKey.fromValidBytes(Uint8List secret, {int keyLength = TweetNaCl.signingKeyLength}) - : super(secret, keyLength); + : super(secret, keyLength: keyLength); SigningKey.fromSeed(Uint8List seed) : this.fromValidBytes(_seedToSecret(seed)); @@ -86,7 +88,7 @@ class SigningKey extends AsymmetricPrivateKey with Suffix implements Sign { SigningKey.decode(String keyString, [Encoder coder = decoder]) : this.fromValidBytes(coder.decode(keyString)); - static const decoder = Bech32Coder(hrp: 'ed25519_sk'); + static const decoder = Bech32Encoder(hrp: 'ed25519_sk'); @override Encoder get encoder => decoder; @@ -139,7 +141,8 @@ class SigningKey extends AsymmetricPrivateKey with Suffix implements Sign { class SignedMessage extends ByteList with Suffix implements EncryptionMessage { SignedMessage({required SignatureBase signature, required Uint8List message}) - : super(signature + message, signatureLength); + : super.withConstraint(signature + message, + constraintLength: signatureLength); SignedMessage.fromList({required Uint8List signedMessage}) : super(signedMessage); diff --git a/pubspec.yaml b/pubspec.yaml index 0f78d62..99ab074 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: pinenacl description: The Dart implementation of the PyNaCl APIs with the TweetNaCl cryptographic library -version: 0.4.2 +version: 0.5.0 homepage: https://github.com/ilap/pinenacl-dart environment: diff --git a/test/base_test.dart b/test/base_test.dart index 3c8f739..3205c22 100644 --- a/test/base_test.dart +++ b/test/base_test.dart @@ -7,7 +7,7 @@ void main() { group('ByteList', () { test('Immutability', () { final l32 = List.generate(32, (i) => 0xb).toUint8List(); - final byteList = ByteList(l32, 32); + final byteList = ByteList(l32); final sk = PrivateKey(l32); expect(() { @@ -27,7 +27,7 @@ void main() { test('Growing', () { final l32 = List.generate(32, (i) => 0xb).toUint8List(); - final byteList = ByteList(l32, 32); + final byteList = ByteList(l32); final sk = PrivateKey(l32); expect(() { diff --git a/test/box_test.dart b/test/box_test.dart index fd71d7f..7adb0b1 100644 --- a/test/box_test.dart +++ b/test/box_test.dart @@ -27,7 +27,7 @@ const _vectors = { }; void main() { - const hex = HexCoder.instance; + const hex = Base16Encoder.instance; group('Public Key Encryption', () { final pub = PublicKey.decode( 'ec2bee2d5be613ca82e377c96a0bf2220d823ce980cdff6279473edc52862798', @@ -96,7 +96,7 @@ void main() { // The x25519_pk must be the same as with the converted ed25519_pk assert(ed25519Pub2 == ed25519Pub3); assert(ed25519Pub2 == ed25519Prv3.publicKey); - assert(ed25519_sk == ed25519Priv.encode(HexCoder.instance)); + assert(ed25519_sk == ed25519Priv.encode(Base16Encoder.instance)); }); test( @@ -160,7 +160,7 @@ void main() { final decrypted = box.decrypt(ByteList(hex.decode(ciphertext)), nonce: hex.decode(nonce)); - assert(hex.encode(ByteList.fromList(decrypted)) == plaintext); + assert(hex.encode(ByteList(decrypted)) == plaintext); }); test('Test Box encryption and decryption combined', () { diff --git a/test/diffie_hellman_test.dart b/test/diffie_hellman_test.dart index d24d97e..d2f63ec 100644 --- a/test/diffie_hellman_test.dart +++ b/test/diffie_hellman_test.dart @@ -6,7 +6,7 @@ import 'package:test/test.dart'; import 'package:pinenacl/api.dart'; import 'package:pinenacl/tweetnacl.dart'; -const hex = HexCoder.instance; +const hex = Base16Encoder.instance; void _doShared(String sk, String pk, String sharedSecret) { final bobpriv = PrivateKey.decode(sk, hex); diff --git a/test/hashing_test.dart b/test/hashing_test.dart index 20b63e0..322fd2e 100644 --- a/test/hashing_test.dart +++ b/test/hashing_test.dart @@ -7,7 +7,7 @@ import 'package:pinenacl/digests.dart'; import 'package:test/test.dart'; void main() { - const hex = HexCoder.instance; + const hex = Base16Encoder.instance; group('Hashing', () { group('SHA-256', () { final dir = Directory.current; diff --git a/test/hmac_test.dart b/test/hmac_test.dart index ed64ce3..c20da62 100644 --- a/test/hmac_test.dart +++ b/test/hmac_test.dart @@ -120,7 +120,7 @@ const vectors = [ ]; void main() { - const hex = HexCoder.instance; + const hex = Base16Encoder.instance; group('Hash-based message authentication code', () { group('HMAC-SHA-', () { var idx = 0; diff --git a/test/pbkdf_test.dart b/test/pbkdf_test.dart index 79d27a7..99f1ba6 100644 --- a/test/pbkdf_test.dart +++ b/test/pbkdf_test.dart @@ -9,7 +9,7 @@ import 'package:pinenacl/encoding.dart'; import 'package:pinenacl/key_derivation.dart'; void main() { - const hex = HexCoder.instance; + const hex = Base16Encoder.instance; group('Password Based Key Derivation Function #2 (PBKDF2)', () { final dir = Directory.current; diff --git a/test/secretbox_test.dart b/test/secretbox_test.dart index 4e88580..408c39f 100644 --- a/test/secretbox_test.dart +++ b/test/secretbox_test.dart @@ -21,7 +21,7 @@ const _vectors = { }; void main() { - const hex = HexCoder.instance; + const hex = Base16Encoder.instance; group('Secret Key Encryption', () { test('SecretBox basic', () { final s = SecretBox.decode( diff --git a/test/signing_test.dart b/test/signing_test.dart index e71cc56..b16c5e6 100644 --- a/test/signing_test.dart +++ b/test/signing_test.dart @@ -37,7 +37,7 @@ const _cardanoVectors = [ ]; void main() { - const hex = HexCoder.instance; + const hex = Base16Encoder.instance; group('Digital Signatures #1', () { group('Signing and/or Verifying tests', () { test('Simple signing and verifying test', () { diff --git a/test/tweetnacl_validation_test.dart b/test/tweetnacl_validation_test.dart index 0b8d631..f22db75 100644 --- a/test/tweetnacl_validation_test.dart +++ b/test/tweetnacl_validation_test.dart @@ -7,7 +7,7 @@ import 'package:pinenacl/tweetnacl.dart' show TweetNaCl; /// The [`NaCl`](https://nacl.cr.yp.to/valid.html) official testvectors from the /// [Cryptography in NaCl](https://cr.yp.to/highspeed/naclcrypto-20090310.pdf) paper void main() { - const hex = HexCoder.instance; + const hex = Base16Encoder.instance; const aliceSk = '77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a'; const alicePk =