Skip to content

Commit a7c86f5

Browse files
committedMay 14, 2023
Export methods and update documentation
- Export codecs - Update documentation - Truncate seed to 32-bit integer for xxh32
1 parent fc2ca90 commit a7c86f5

24 files changed

+53
-35
lines changed
 

‎CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 1.11.2
2+
3+
- Export codecs
4+
- Update documentation
5+
- Truncate seed to 32-bit integer for xxh32
6+
17
# 1.11.1
28

39
- Export a few additional clases

‎README.md

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ Examples can be found inside the `example` folder.
7777

7878
```dart
7979
import 'package:hashlib/hashlib.dart';
80-
import 'package:hashlib/src/codecs_base.dart';
8180
8281
void main() {
8382
var text = "Happy Hashing!";

‎example/hashlib_example.dart

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:hashlib/hashlib.dart';
2-
import 'package:hashlib/src/codecs_base.dart';
32

43
void main() {
54
var text = "Happy Hashing!";

‎example/otpauth_parser.dart

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'dart:typed_data';
22

33
import 'package:hashlib/hashlib.dart';
4-
import 'package:hashlib/src/codecs_base.dart';
54

65
/// Parse any otpauth URI
76
OTPAuth parse(String keyUri) {

‎lib/src/algorithms/xxh32_32bit.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class XXHash32Sink extends BlockHashSink {
3232
@override
3333
void reset() {
3434
super.reset();
35-
_acc1 = seed + prime32_1 + prime32_2;
36-
_acc2 = seed + prime32_2;
37-
_acc3 = seed + 0;
38-
_acc4 = seed - prime32_1;
35+
_acc1 = (seed & _mask32) + prime32_1 + prime32_2;
36+
_acc2 = (seed & _mask32) + prime32_2;
37+
_acc3 = (seed & _mask32) + 0;
38+
_acc4 = (seed & _mask32) - prime32_1;
3939
}
4040

4141
@override
@@ -94,7 +94,7 @@ class XXHash32Sink extends BlockHashSink {
9494
int _hash;
9595

9696
if (messageLength < 16) {
97-
_hash = seed + prime32_5;
97+
_hash = (seed & _mask32) + prime32_5;
9898
} else {
9999
_hash = rotl32(_acc1, 1);
100100
_hash += rotl32(_acc2, 7);

‎lib/src/algorithms/xxh32_64bit.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class XXHash32Sink extends BlockHashSink {
3333
@override
3434
void reset() {
3535
super.reset();
36-
_acc1 = seed + prime32_1 + prime32_2;
37-
_acc2 = seed + prime32_2;
38-
_acc3 = seed + 0;
39-
_acc4 = seed - prime32_1;
36+
_acc1 = (seed & _mask32) + prime32_1 + prime32_2;
37+
_acc2 = (seed & _mask32) + prime32_2;
38+
_acc3 = (seed & _mask32) + 0;
39+
_acc4 = (seed & _mask32) - prime32_1;
4040
}
4141

4242
@override
@@ -80,7 +80,7 @@ class XXHash32Sink extends BlockHashSink {
8080
int _hash;
8181

8282
if (messageLength < 16) {
83-
_hash = seed + prime32_5;
83+
_hash = (seed & _mask32) + prime32_5;
8484
} else {
8585
_hash = (_acc1 << 1) | (_acc1 >>> 31);
8686
_hash += (_acc2 << 7) | (_acc2 >>> 25);

‎lib/src/codecs_base.dart

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Copyright (c) 2023, Sudipto Chandra
22
// All rights reserved. Check LICENSE file for details.
33

4-
export 'codecs/ascii.dart';
5-
export 'codecs/base16.dart';
6-
export 'codecs/base32.dart';
7-
export 'codecs/base64.dart';
8-
export 'codecs/base64url.dart';
4+
export 'codecs/ascii.dart' hide ASCIICodec;
5+
export 'codecs/base16.dart' hide B16Codec;
6+
export 'codecs/base32.dart' hide B32Codec;
7+
export 'codecs/base64.dart' hide B64Codec;
8+
export 'codecs/base64url.dart' hide B64URLCodec;
9+
export 'codecs/codec.dart';
10+
export 'codecs/converter.dart';

‎lib/src/hashlib_base.dart

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ export 'alder32.dart';
55
export 'argon2.dart';
66
export 'blake2b.dart';
77
export 'blake2s.dart';
8-
export 'codecs/codec.dart' show Uint8Codec;
9-
export 'core/block_hash.dart' show BlockHashBase, BlockHashSink;
10-
export 'core/hash_base.dart' show HashBase, HashDigestSink;
11-
export 'core/hash_digest.dart' show HashDigest;
8+
export 'codecs_base.dart';
9+
export 'core/block_hash.dart';
10+
export 'core/hash_base.dart';
11+
export 'core/hash_digest.dart';
12+
export 'core/kdf_base.dart';
13+
export 'core/mac_base.dart';
1214
export 'crc16.dart';
1315
export 'crc32.dart';
1416
export 'crc64.dart';
@@ -22,7 +24,7 @@ export 'otpauth.dart';
2224
export 'pbkdf2.dart';
2325
export 'poly1305.dart';
2426
export 'random.dart';
25-
export 'registry.dart' show BlockHashRegistry, HashRegistry;
27+
export 'registry.dart';
2628
export 'ripemd128.dart';
2729
export 'ripemd160.dart';
2830
export 'ripemd256.dart';

‎lib/src/md5.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:hashlib/src/core/block_hash.dart';
88
import 'package:hashlib/src/core/hash_digest.dart';
99

1010
/// MD5 can be used as a checksum to verify data integrity against unintentional
11-
/// corruption. Although it was widely used as a cryptographic has function
11+
/// corruption. Although it was widely used as a cryptographic hash function
1212
/// once, it has been found to suffer from extensive vulnerabilities.
1313
///
1414
/// **WARNING: It should not be used for cryptographic purposes.**

‎lib/src/xxh128.dart

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class XXH128 extends BlockHashBase {
3030
final int seed;
3131
final List<int>? secret;
3232

33+
/// Creates a new instance of [XXH128].
34+
///
35+
/// Paramters:
36+
/// - [seed] is an optional 64-bit integer. Default: 0
37+
/// - [secret] is an array of bytes. The length should be at least 136.
38+
/// - If the [secret] is present, the [seed] is ignored.
3339
const XXH128({this.seed = 0, this.secret});
3440

3541
@override

‎lib/src/xxh3.dart

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class XXH3 extends BlockHashBase {
3030
final int seed;
3131
final List<int>? secret;
3232

33+
/// Creates a new instance of [XXH3].
34+
///
35+
/// Paramters:
36+
/// - [seed] is an optional 64-bit integer. Default: 0
37+
/// - [secret] is an array of bytes. The length should be at least 136.
38+
/// - If the [secret] is present, the [seed] is ignored.
3339
const XXH3({this.seed = 0, this.secret});
3440

3541
@override

‎lib/src/xxh32.dart

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const XXHash32 xxh32 = XXHash32(0);
2323
class XXHash32 extends BlockHashBase {
2424
final int seed;
2525

26+
/// Creates a new instance of [XXHash32].
27+
///
28+
/// Paramters:
29+
/// - [seed] is an optional 32-bit integer. Default: 0
2630
const XXHash32([this.seed = 0]);
2731

2832
@override

‎lib/src/xxh64.dart

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const XXHash64 xxh64 = XXHash64(0);
2323
class XXHash64 extends BlockHashBase {
2424
final int seed;
2525

26+
/// Creates a new instance of [XXHash64].
27+
///
28+
/// Paramters:
29+
/// - [seed] is an optional 64-bit integer. Default: 0
2630
const XXHash64([this.seed = 0]);
2731

2832
@override

‎pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: hashlib
22
description: Secure hash functions, checksum generators, and key derivation algorithms optimized for Dart.
33
homepage: https://github.com/dipu-bd/hashlib
4-
version: 1.11.1
4+
version: 1.11.2
55

66
environment:
77
sdk: ">=2.14.0 <4.0.0"

‎test/argon2_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// All rights reserved. Check LICENSE file for details.
33

44
import 'package:hashlib/hashlib.dart';
5-
import 'package:hashlib/src/codecs_base.dart';
65
import 'package:test/test.dart';
76

87
void main() {

‎test/base16_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// All rights reserved. Check LICENSE file for details.
33

44
import 'package:hashlib/hashlib.dart';
5-
import 'package:hashlib/src/codecs_base.dart';
65
import 'package:test/test.dart';
76

87
void main() {

‎test/base32_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2023, Sudipto Chandra
22
// All rights reserved. Check LICENSE file for details.
33

4-
import 'package:hashlib/src/codecs_base.dart';
4+
import 'package:hashlib/hashlib.dart';
55
import 'package:test/test.dart';
66

77
void main() {

‎test/base64_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import 'dart:convert';
55

66
import 'package:hashlib/hashlib.dart';
7-
import 'package:hashlib/src/codecs_base.dart';
87
import 'package:test/test.dart';
98

109
void main() {

‎test/base64url_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import 'dart:convert';
55

66
import 'package:hashlib/hashlib.dart';
7-
import 'package:hashlib/src/codecs_base.dart';
87
import 'package:test/test.dart';
98

109
void main() {

‎test/compare_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:typed_data';
66

77
import 'package:crypto/crypto.dart' as crypto;
88
import 'package:hashlib/hashlib.dart';
9-
import 'package:hashlib/src/codecs_base.dart';
109
import 'package:pointycastle/digests/blake2b.dart' as pc_blake2b;
1110
import 'package:pointycastle/digests/keccak.dart' as pc_keccak;
1211
import 'package:pointycastle/digests/sha3.dart' as pc_sha3;

‎test/poly1305_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import 'package:hashlib/hashlib.dart';
55
import 'package:hashlib/src/algorithms/poly1305.dart';
6-
import 'package:hashlib/src/codecs_base.dart';
76
import 'package:test/test.dart';
87

98
const cases = [

‎test/sha3_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// All rights reserved. Check LICENSE file for details.
33

44
import 'package:hashlib/hashlib.dart';
5-
import 'package:hashlib/src/codecs_base.dart';
65
import 'package:test/test.dart';
76

87
void main() {

‎test/xxh128_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
})
77

88
import 'package:hashlib/hashlib.dart';
9-
import 'package:hashlib/src/codecs_base.dart';
109
import 'package:test/test.dart';
1110

1211
const seed = 0x9e3779b185ebca8d;

‎test/xxh3_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
})
77

88
import 'package:hashlib/hashlib.dart';
9-
import 'package:hashlib/src/codecs_base.dart';
109
import 'package:test/test.dart';
1110

1211
const seed = 0x9e3779b185ebca8d;

0 commit comments

Comments
 (0)
Please sign in to comment.