ilap / pinenacl-dart

The Dart implementation of the PyNaCl API with the TweetNaCl cryptographic library
MIT License
36 stars 4 forks source link

Run benchmark meet exception #13

Closed Tougee closed 3 years ago

Tougee commented 3 years ago
❯ pub run benchmark/all_benchmark.dart
| 2021-07-02 15:14:12 | Digest | BLAKE2B | 30.58 MB/s | 153 iterations | 5003 ms | 153.00 MB |
| 2021-07-02 15:14:17 | Digest | SHA-256 | 64.14 MB/s | 321 iterations | 5004 ms | 321.00 MB |
| 2021-07-02 15:14:22 | Digest | SHA-512 | 19.49 MB/s | 98 iterations | 5027 ms | 98.00 MB |
Unhandled exception:
type 'Null' is not a subtype of type 'int' in type cast
#0      List.length= (dart:core-patch/growable_array.dart:222:12)
#1      _IntListMixin.+ (dart:typed_data-patch/typed_data_patch.dart:156:9)
#2      SigningKey._seedToSecret (package:pinenacl/src/signatures/ed25519.dart:121:33)
#3      new SigningKey.fromSeed (package:pinenacl/src/signatures/ed25519.dart:83:29)
#4      new SigningKey.generate (package:pinenacl/src/signatures/ed25519.dart:86:14)
#5      SignatureBenchmark.setup (file:///Users/touge/dev/dart/pinenacl-dart/benchmark/helpers/signature_benchmark.dart:19:26)
#6      BenchmarkBase.measure (package:benchmark_harness/src/benchmark_base.dart:52:5)
#7      BenchmarkBase.report (package:benchmark_harness/src/benchmark_base.dart:62:24)
#8      main (file:///Users/touge/dev/dart/pinenacl-dart/benchmark/tweetnacl/ed25519_benchmark.dart:28:39)
#9      main (file:///Users/touge/dev/dart/pinenacl-dart/benchmark/all_benchmark.dart:16:3)
#10     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
#11     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

It can be fixed by

+++ b/lib/src/signatures/ed25519.dart
@@ -118,7 +118,7 @@ class SigningKey extends AsymmetricPrivateKey implements Sign {
     //}

     final priv =
-        Uint8List.fromList(seed + Uint8List(TweetNaCl.publicKeyLength));
+        Uint8List.fromList([...seed, ...Uint8List(TweetNaCl.publicKeyLength)]);
     final pub = Uint8List(TweetNaCl.publicKeyLength);
     TweetNaCl.crypto_sign_keypair(pub, priv, Uint8List.fromList(seed));

Not sure you can accept this

ilap commented 3 years ago

Thx for that I am checking it. Can you pls let me know some details? Which dart version and platform/arch do you use? As it works for me with the latest stable.

ilap@nyx:~/Projects/pinenacl-dart$ dart --version
Dart SDK version: 2.13.4 (stable) (Wed Jun 23 13:08:41 2021 +0200) on "linux_x64"
ilap@nyx:~/Projects/pinenacl-dart$ uname -a 
Linux nyx 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Tougee commented 3 years ago

Whoops, it's a problem with my low Dart version.