Skip to content

Commit

Permalink
Exports hashlib_codecs from current package
Browse files Browse the repository at this point in the history
  • Loading branch information
dipu-bd committed Sep 11, 2024
1 parent e540c2e commit 0b33aaf
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.20.3

- Exports hashlib_codecs from current package. To get it: `import 'package:hashlib/codecs.dart';`

# 1.20.2

- Modifies `Poly1305` interface: `poly1305` is now available as the builder.
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ Check the [API Reference](https://pub.dev/documentation/hashlib/latest/) for det
Examples can be found inside the `example` folder.

```dart
import 'package:hashlib/codecs.dart';
import 'package:hashlib/hashlib.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';
void main() {
var text = "Happy Hashing!";
Expand Down Expand Up @@ -164,10 +164,10 @@ void main() {
print('');
// Examples of PBKDF2 key derivation
print("SHA256/HMAC/PBKDF2 => ${pbkdf2(pw, iv, 100).hex()}");
print("SHA1/HMAC/PBKDF2 => ${sha1.pbkdf2(iv, 100).hex(pw)}");
print("BLAKE2b-256/HMAC/PBKDF2 => ${blake2b256.pbkdf2(iv, 100).hex(pw)}");
print("BLAKE2b-256/MAC/PBKDF2 => ${blake2b256.mac.pbkdf2(iv, 100).hex(pw)}");
print("SHA256/HMAC/PBKDF2 => ${pbkdf2(pw, iv).hex()}");
print("BLAKE2b-256/HMAC/PBKDF2 => ${blake2b256.pbkdf2(iv).hex(pw)}");
print("BLAKE2b-256/MAC/PBKDF2 => ${blake2b256.mac.pbkdf2(iv).hex(pw)}");
print("SHA1/HMAC/PBKDF2 => ${sha1.pbkdf2(iv, iterations: 100).hex(pw)}");
print('');
// Examples of OTP generation
Expand Down
2 changes: 1 addition & 1 deletion example/hashlib_example.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:hashlib/codecs.dart';
import 'package:hashlib/hashlib.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';

void main() {
var text = "Happy Hashing!";
Expand Down
2 changes: 1 addition & 1 deletion example/otpauth_parser.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:typed_data';

import 'package:hashlib/codecs.dart';
import 'package:hashlib/hashlib.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';

/// Parse any otpauth URI
OTPAuth parse(String keyUri) {
Expand Down
7 changes: 7 additions & 0 deletions lib/codecs.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2024, Sudipto Chandra
// All rights reserved. Check LICENSE file for details.

/// Implementations of fast and error resilient codecs
library hashlib_codecs;

export 'package:hashlib_codecs/hashlib_codecs.dart';
2 changes: 1 addition & 1 deletion lib/src/algorithms/argon2/argon2.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2023, Sudipto Chandra
// All rights reserved. Check LICENSE file for details.

import 'package:hashlib/codecs.dart';
import 'package:hashlib/src/core/kdf_base.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';

import 'argon2_64bit.dart' if (dart.library.js) 'argon2_32bit.dart';
import 'common.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/algorithms/argon2/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import 'dart:typed_data';

import 'package:hashlib/codecs.dart';
import 'package:hashlib/src/core/hash_digest.dart';
import 'package:hashlib/src/random.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';

const int _slices = 4;
const int _minParallelism = 1;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/algorithms/bcrypt/bcrypt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import 'dart:typed_data';

import 'package:hashlib/codecs.dart';
import 'package:hashlib/src/algorithms/bcrypt/common.dart';
import 'package:hashlib/src/algorithms/bcrypt/security.dart';
import 'package:hashlib/src/core/kdf_base.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';

class Bcrypt extends KeyDerivatorBase {
final BcryptContext _ctx;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/algorithms/bcrypt/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import 'dart:typed_data';

import 'package:hashlib/codecs.dart';
import 'package:hashlib/src/algorithms/bcrypt/bcrypt.dart';
import 'package:hashlib/src/core/hash_digest.dart';
import 'package:hashlib/src/random.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';

enum BcryptVersion {
/// This is a revised version of original v2 with UTF-8 character support
Expand Down
2 changes: 1 addition & 1 deletion lib/src/argon2.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2023, Sudipto Chandra
// All rights reserved. Check LICENSE file for details.

import 'package:hashlib/codecs.dart';
import 'package:hashlib/src/algorithms/argon2/argon2.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';

export 'package:hashlib/src/algorithms/argon2/argon2.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/src/bcrypt.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) 2024, Sudipto Chandra
// All rights reserved. Check LICENSE file for details.

import 'package:hashlib/codecs.dart';
import 'package:hashlib/src/algorithms/bcrypt/bcrypt.dart';
import 'package:hashlib/src/algorithms/bcrypt/common.dart';
import 'package:hashlib/src/algorithms/bcrypt/security.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';

export 'algorithms/bcrypt/bcrypt.dart' show Bcrypt;
export 'algorithms/bcrypt/common.dart'
Expand Down
13 changes: 9 additions & 4 deletions lib/src/core/hash_digest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import 'dart:convert' as cvt;
import 'dart:typed_data';

import 'package:hashlib_codecs/hashlib_codecs.dart';
import 'package:hashlib/codecs.dart';

class HashDigest extends Object {
final Uint8List bytes;
Expand Down Expand Up @@ -120,12 +120,17 @@ class HashDigest extends Object {
return isEqual(Uint8List.view(other.buffer));
} else if (other is String) {
return isEqual(fromHex(other));
} else if (other is Iterable<int>) {
if (other is List<int>) {
if (other.length != bytes.length) {
} else if (other is List<int>) {
if (other.length != bytes.length) {
return false;
}
for (int i = 0; i < bytes.length; ++i) {
if (other[i] != bytes[i++]) {
return false;
}
}
return true;
} else if (other is Iterable<int>) {
int i = 0;
for (int x in other) {
if (i >= bytes.length || x != bytes[i++]) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: hashlib
description: Secure hash functions, checksum generators, and key derivation algorithms optimized for Dart.
homepage: https://github.com/bitanon/hashlib
version: 1.20.2
version: 1.20.3

environment:
sdk: '>=2.14.0 <4.0.0'
Expand Down
2 changes: 1 addition & 1 deletion test/argon2_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import 'dart:typed_data';

import 'package:hashlib/codecs.dart';
import 'package:hashlib/hashlib.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';
import 'package:test/test.dart';

void main() {
Expand Down
2 changes: 1 addition & 1 deletion test/bcrypt_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import 'dart:convert';

import 'package:hashlib/codecs.dart';
import 'package:hashlib/hashlib.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';
import 'package:test/test.dart';

void main() {
Expand Down
2 changes: 1 addition & 1 deletion test/compare_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import 'dart:io';
import 'dart:typed_data';

import 'package:crypto/crypto.dart' as crypto;
import 'package:hashlib/codecs.dart';
import 'package:hashlib/hashlib.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';
import 'package:pointycastle/digests/blake2b.dart' as pc_blake2b;
import 'package:pointycastle/digests/keccak.dart' as pc_keccak;
import 'package:pointycastle/digests/md4.dart' as pc_md4;
Expand Down
5 changes: 5 additions & 0 deletions test/core/hash_digest_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ void main() {
expect(digest.isEqual(byteArray), isTrue);
});

test('isEqual returns true for equal byte iterables', () {
final byteIterables = {1, 2, 3, 4, 5, 6, 7, 8};
expect(digest.isEqual(byteIterables), isTrue);
});

test('isEqual returns true for equal ByteBuffer', () {
final buffer = bytes.buffer;
expect(digest.isEqual(buffer), isTrue);
Expand Down
2 changes: 1 addition & 1 deletion test/poly1305_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import 'dart:typed_data';

import 'package:hashlib/codecs.dart';
import 'package:hashlib/hashlib.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';
import 'package:test/test.dart';

const cases = [
Expand Down
2 changes: 1 addition & 1 deletion test/sha3_test.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2023, Sudipto Chandra
// All rights reserved. Check LICENSE file for details.

import 'package:hashlib/codecs.dart';
import 'package:hashlib/hashlib.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';
import 'package:test/test.dart';

void main() {
Expand Down
2 changes: 1 addition & 1 deletion test/xxh128_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import 'dart:typed_data';

import 'package:hashlib/codecs.dart';
import 'package:hashlib/hashlib.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';
import 'package:test/test.dart';

const seed = 0x9e3779b185ebca8d;
Expand Down
2 changes: 1 addition & 1 deletion test/xxh3_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import 'dart:typed_data';

import 'package:hashlib/codecs.dart';
import 'package:hashlib/hashlib.dart';
import 'package:hashlib_codecs/hashlib_codecs.dart';
import 'package:test/test.dart';

const seed = 0x9e3779b185ebca8d;
Expand Down

0 comments on commit 0b33aaf

Please sign in to comment.