Skip to content

Commit

Permalink
Bump version of the hashlib_codecs
Browse files Browse the repository at this point in the history
- **Breaking**: The `HashDigest.base32` and `HashDigest.base64` will have padding by default.
- Bump version of the [hashlib_codecs](https://pub.dev/packages/hashlib_codecs)
  • Loading branch information
dipu-bd committed Jun 22, 2023
1 parent c507496 commit 9c0d18e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.12.0

- **Breaking**: The `HashDigest.base32` and `HashDigest.base64` will have padding by default.
- Bump version of the [hashlib_codecs](https://pub.dev/packages/hashlib_codecs)

# 1.11.4

- Move codecs to separate package: [hashlib_codecs](https://github.com/bitanon/hashlib_codecs)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

This library contains implementations of secure hash functions, checksum generators, and key derivation algorithms optimized for Dart.

> Checkout the [hashlib_codecs](https://pub.dev/packages/hashlib_codecs) that is being used by this package to encode and decode bytes.
## Features

### Block Hash Algorithms
Expand Down
19 changes: 11 additions & 8 deletions lib/src/core/hash_digest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,30 @@ class HashDigest extends Object {
@override
String toString() => hex();

/// The message digest as a binary string with zero padding.
/// The message digest as a binary string.
String binary() => toBinary(bytes);

/// The message digest as a hexadecimal string with zero padding.
/// The message digest as a octal string.
String octal() => toOctal(bytes);

/// The message digest as a hexadecimal string.
///
/// Parameters:
/// - If [upper] is true, the string will be in uppercase alphabets.
String hex([bool upper = false]) => toHex(bytes, upper: upper);

/// The message digest as a Base-32 string with no padding.
/// The message digest as a Base-32 string.
///
/// If [upper] is true, the output will have uppercase alphabets.
/// If [padding] is true, the output will have `=` padding at the end.
String base32({bool upper = true, bool padding = false}) =>
String base32({bool upper = true, bool padding = true}) =>
toBase32(bytes, lower: !upper, padding: padding);

/// The message digest as a Base-64 string with no padding.
///
/// If [urlSafe] is true, the output will have URL-safe base64 alphabets.
/// If [padding] is true, the output will have `=` padding at the end.
String base64({bool urlSafe = false, bool padding = false}) =>
String base64({bool urlSafe = false, bool padding = true}) =>
toBase64(bytes, padding: padding, url: urlSafe);

/// The message digest as a BigInt.
Expand All @@ -47,15 +50,15 @@ class HashDigest extends Object {
/// endian number; Otherwise, if [endian] is [Endian.big], it will treat the
/// digest bytes as a big endian number.
BigInt bigInt({Endian endian = Endian.little}) =>
toBigInt(bytes, endian: endian);
toBigInt(bytes, msbFirst: endian == Endian.big);

/// Gets 64-bit unsiged integer from the message digest.
///
/// If [endian] is [Endian.little], it will treat the digest bytes as a little
/// endian number; Otherwise, if [endian] is [Endian.big], it will treat the
/// digest bytes as a big endian number.
int number([Endian endian = Endian.big]) =>
toBigInt(bytes, endian: endian).toUnsigned(64).toInt();
toBigInt(bytes, msbFirst: endian == Endian.big).toUnsigned(64).toInt();

/// The message digest as a string of ASCII alphabets.
String ascii() => cvt.ascii.decode(bytes);
Expand Down Expand Up @@ -91,7 +94,7 @@ class HashDigest extends Object {
} else if (other is TypedData && other is! Uint8List) {
return isEqual(other.buffer.asUint8List());
} else if (other is String) {
return isEqual(base16.decodeFromString(other));
return isEqual(fromHex(other));
} else if (other is Iterable<int>) {
if (other is List<int>) {
if (other.length != bytes.length) {
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: hashlib
description: Secure hash functions, checksum generators, and key derivation algorithms optimized for Dart.
homepage: https://github.com/bitanon/hashlib
version: 1.11.4
version: 1.12.0

environment:
sdk: ">=2.14.0 <4.0.0"
sdk: '>=2.14.0 <4.0.0'

platforms:
android:
Expand All @@ -15,7 +15,7 @@ platforms:
windows:

dependencies:
hashlib_codecs: ^1.2.0
hashlib_codecs: ^2.1.0

dev_dependencies:
lints: ^1.0.1
Expand Down

0 comments on commit 9c0d18e

Please sign in to comment.