|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
| 15 | +import 'dart:ffi'; |
15 | 16 | import 'dart:typed_data'; |
16 | 17 |
|
17 | 18 | import 'package:cryptography/cryptography.dart'; |
@@ -87,33 +88,32 @@ void main() { |
87 | 88 | } |
88 | 89 | }); |
89 | 90 |
|
90 | | - test('SecretKeyData([...], overwriteWhenDestroyed: true)', () { |
91 | | - final inputs = [ |
92 | | - [42, 43, 44], |
93 | | - Uint8List.fromList([42, 43, 44]) |
94 | | - ]; |
95 | | - for (var input in inputs) { |
96 | | - final a = SecretKeyData(input, overwriteWhenDestroyed: true); |
97 | | - final capturedBytes = a.bytes; |
98 | | - expect(capturedBytes, [42, 43, 44]); |
| 91 | + test('SecretKeyData(Uint8List(...), overwriteWhenDestroyed: true)', () { |
| 92 | + final bytes = Uint8List.fromList([42, 43, 44]); |
| 93 | + final secretKey = SecretKeyData(bytes, overwriteWhenDestroyed: true); |
| 94 | + expect(secretKey.bytes, [42, 43, 44]); |
99 | 95 |
|
100 | | - a.destroy(); |
101 | | - expect(input, [0, 0, 0]); |
102 | | - expect(() => a.bytes, throwsStateError); |
103 | | - expect(() => capturedBytes[0], throwsStateError); |
104 | | - } |
| 96 | + secretKey.destroy(); |
| 97 | + expect(bytes, [0, 0, 0]); |
| 98 | + expect(() => secretKey.bytes, throwsStateError); |
105 | 99 | }); |
106 | 100 |
|
107 | | - test('SecretKeyData(const [...], overwriteWhenDestroyed: true)', () { |
108 | | - const data = [42, 43, 44]; |
109 | | - final a = SecretKeyData(data, overwriteWhenDestroyed: true); |
110 | | - final capturedBytes = a.bytes; |
111 | | - expect(capturedBytes, [42, 43, 44]); |
| 101 | + test('SecretKeyData([...], overwriteWhenDestroyed: true)', () { |
| 102 | + final bytes = [42, 43, 44]; |
| 103 | + final secretKey = SecretKeyData(bytes, overwriteWhenDestroyed: true); |
| 104 | + expect(secretKey.bytes, [42, 43, 44]); |
| 105 | + secretKey.destroy(); |
| 106 | + expect(bytes, [42, 43, 44]); |
| 107 | + expect(() => secretKey.bytes, throwsStateError); |
| 108 | + }); |
112 | 109 |
|
113 | | - a.destroy(); |
114 | | - expect(data, [42, 43, 44]); |
115 | | - expect(() => a.bytes, throwsStateError); |
116 | | - expect(() => capturedBytes[0], throwsStateError); |
| 110 | + test('SecretKeyData(Uint8List(...), overwriteWhenDestroyed: false)', () { |
| 111 | + final bytes = Uint8List.fromList([42, 43, 44]); |
| 112 | + final secretKey = SecretKeyData(bytes, overwriteWhenDestroyed: false); |
| 113 | + expect(secretKey.bytes, [42, 43, 44]); |
| 114 | + secretKey.destroy(); |
| 115 | + expect(bytes, [42, 43, 44]); |
| 116 | + expect(() => secretKey.bytes, throwsStateError); |
117 | 117 | }); |
118 | 118 |
|
119 | 119 | test('SecretKeyData.random()', () { |
|
0 commit comments