Skip to content

Commit f37e844

Browse files
committed
Refactoring internal identifiers.
1 parent 1d51dd3 commit f37e844

File tree

14 files changed

+49
-45
lines changed

14 files changed

+49
-45
lines changed

cryptography/lib/src/cryptography/mac_algorithm.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class _EmptyMacSink extends MacSink with DartMacSinkMixin {
252252
bool get isClosed => _isClosed;
253253

254254
@override
255-
Uint8List get macStateAsUint8List => _empty;
255+
Uint8List get macBytes => _empty;
256256

257257
@override
258258
void addSlice(List<int> chunk, int start, int end, bool isLast) {
@@ -303,7 +303,7 @@ class _MacSink extends MacSink with DartMacSinkMixin {
303303
bool get isClosed => _macFuture != null;
304304

305305
@override
306-
Uint8List get macStateAsUint8List {
306+
Uint8List get macBytes {
307307
throw UnimplementedError();
308308
}
309309

cryptography/lib/src/dart/_helpers.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ class PackageCryptoHashSink extends DartHashSink {
9090
bool _isClosed = false;
9191

9292
@override
93-
final Uint8List hashBufferAsUint8List;
93+
final Uint8List hashBytes;
9494

95-
PackageCryptoHashSink(this.hashBufferAsUint8List, this.hashAlgorithm,
96-
this._sink, this._captureSink);
95+
PackageCryptoHashSink(
96+
this.hashBytes, this.hashAlgorithm, this._sink, this._captureSink);
9797

9898
@override
9999
bool get isClosed => _isClosed;
@@ -130,7 +130,7 @@ class PackageCryptoHashSink extends DartHashSink {
130130
}
131131
_isClosed = true;
132132
_sink.close();
133-
hashBufferAsUint8List.setAll(0, _captureSink._result!.bytes);
133+
hashBytes.setAll(0, _captureSink._result!.bytes);
134134
}
135135

136136
@override

cryptography/lib/src/dart/blake2b_impl_browser.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Blake2bSink extends DartHashSink {
6565
final _hash = Uint32List(32);
6666

6767
@override
68-
late final Uint8List hashBufferAsUint8List = Uint8List.view(
68+
late final Uint8List hashBytes = Uint8List.view(
6969
_hash.buffer,
7070
0,
7171
64,

cryptography/lib/src/dart/blake2b_impl_vm.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Blake2bSink extends DartHashSink {
5454
);
5555

5656
@override
57-
late final Uint8List hashBufferAsUint8List = Uint8List.view(
57+
late final Uint8List hashBytes = Uint8List.view(
5858
_hash.buffer,
5959
0,
6060
64,

cryptography/lib/src/dart/blake2s.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class _Blake2sSink extends DartHashSink {
6666
int _length = 0;
6767

6868
@override
69-
late final Uint8List hashBufferAsUint8List = Uint8List.view(
69+
late final Uint8List hashBytes = Uint8List.view(
7070
_hash.buffer,
7171
0,
7272
32,

cryptography/lib/src/dart/dart_hash_algorithm.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ mixin DartHashAlgorithmMixin implements DartHashAlgorithm {
4949

5050
/// A [HashSink] that supports synchronous evaluation ([hashSync]).
5151
abstract class DartHashSink extends HashSink {
52-
Uint8List get hashBufferAsUint8List;
52+
/// Unsafe view at the current hash bytes.
53+
///
54+
/// You must copy the bytes if you want to keep them.
55+
Uint8List get hashBytes;
5356

5457
bool get isClosed;
5558

@@ -81,7 +84,7 @@ abstract class DartHashSink extends HashSink {
8184
if (!isClosed) {
8285
throw StateError('Not closed');
8386
}
84-
return Hash(Uint8List.fromList(hashBufferAsUint8List));
87+
return Hash(Uint8List.fromList(hashBytes));
8588
}
8689

8790
void reset();

cryptography/lib/src/dart/dart_mac_algorithm.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ mixin DartMacAlgorithmMixin implements DartMacAlgorithm {
105105

106106
/// A mixin for pure Dart implementations of [MacSink]
107107
mixin DartMacSinkMixin implements MacSink {
108-
/// View at bytes of the latest MAC.
109-
Uint8List get macStateAsUint8List;
108+
/// Unsafe view at the current MAC bytes.
109+
///
110+
/// You must copy the bytes if you want to keep them.
111+
Uint8List get macBytes;
110112

111113
/// Re-initializes the sink.
112114
void initializeSync({
@@ -126,6 +128,6 @@ mixin DartMacSinkMixin implements MacSink {
126128
if (!isClosed) {
127129
throw StateError('Sink is not closed');
128130
}
129-
return Mac(Uint8List.fromList(macStateAsUint8List));
131+
return Mac(Uint8List.fromList(macBytes));
130132
}
131133
}

cryptography/lib/src/dart/hmac.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class _DartHmacSink extends MacSink with DartMacSinkMixin {
9090
bool get isClosed => _isClosed;
9191

9292
@override
93-
Uint8List get macStateAsUint8List => _outerSink.hashBufferAsUint8List;
93+
Uint8List get macBytes => _outerSink.hashBytes;
9494

9595
@override
9696
void addSlice(List<int> chunk, int start, int end, bool isLast) {
@@ -101,7 +101,7 @@ class _DartHmacSink extends MacSink with DartMacSinkMixin {
101101
innerSink.addSlice(chunk, start, end, isLast);
102102
if (isLast) {
103103
_isClosed = true;
104-
final innerDigest = innerSink.hashBufferAsUint8List;
104+
final innerDigest = innerSink.hashBytes;
105105
final outerSink = _outerSink;
106106
outerSink.addSlice(innerDigest, 0, innerDigest.length, true);
107107
}
@@ -135,7 +135,7 @@ class _DartHmacSink extends MacSink with DartMacSinkMixin {
135135
innerSink.reset();
136136
if (hmacKey.length > blockLength) {
137137
innerSink.addSlice(hmacKey, 0, hmacKey.length, true);
138-
hmacKey = Uint8List.fromList(innerSink.hashBufferAsUint8List);
138+
hmacKey = Uint8List.fromList(innerSink.hashBytes);
139139
innerSink.reset();
140140
eraseKey = true;
141141
}

cryptography/lib/src/dart/pbkdf2.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class DartPbkdf2 extends Pbkdf2 {
109109
nonce: nonce,
110110
);
111111
macState.addSlice(previous, 0, previous.length, true);
112-
final macBytes = macState.macStateAsUint8List;
112+
final macBytes = macState.macBytes;
113113

114114
// XOR with the result
115115
for (var bi = 0; bi < block.length; bi++) {

cryptography/lib/src/dart/poly1305.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class DartPoly1305Sink extends MacSink with DartMacSinkMixin {
7777

7878
@override
7979
// TODO: implement macStateAsUint8List
80-
Uint8List get macStateAsUint8List => _mac!.bytes as Uint8List;
80+
Uint8List get macBytes => _mac!.bytes as Uint8List;
8181

8282
@mustCallSuper
8383
@override

0 commit comments

Comments
 (0)