Flutter加密测试用例

huangapple go评论68阅读模式
英文:

Flutter cryptography test case

问题

无法在Flutter测试中使用cryptography库的问题是因为它在测试环境下引发了UnimplementedError错误。但是在实际应用程序中,这个库可以正常工作。您可能无法为此库编写测试用例。

以下是您提供的代码的翻译部分:

import 'package:cryptography/cryptography.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  group("Test ECDH", () {
    test("generate shared secret", () async {
      final algorithm = Ecdh.p256(length: 32);
      final aliceKeyPair = await algorithm.newKeyPair();
    });
  });
}

请注意,要解决UnimplementedError错误,您可能需要等待cryptography库的维护者修复此问题或查看库的文档以了解是否有与测试环境兼容的解决方法。

英文:

Why can not use cryptography on flutter test ?

import 'package:cryptography/cryptography.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  group("Test ECDH", () {
    test("generate shared secret", () async {
      final algorithm = Ecdh.p256(length: 32);
      final aliceKeyPair = await algorithm.newKeyPair();
    });
  });
}

i receive this error :

/opt/flutter/bin/flutter --no-color test --machine --start-paused test/custom_test.dart
Testing started at 9:24 PM ...

package:cryptography/src/dart/ecdh.dart 53:5  DartEcdh.newKeyPair
test/custom_test.dart 8:44                   main.<fn>.<fn>

UnimplementedError

this simple code does work on real application (web or mobile ...)
but i can not write test case for this library !

Note: I test this code on Linux Ubuntu 22.04

答案1

得分: 1

DartEcdh类

在纯Dart中实现了Ecdh(P256、P384、P521)。目前,如果您尝试使用它,它会抛出UnimplementedError。

显然,该包不起作用(在Mac上也尝试过)。

也许在Web版本上它可以运行,使用Web Cryptography API

英文:

DartEcdh class

> Ecdh (P256, P384, P521) implementation in pure Dart. Currently it
> throws UnimplementedError if you try to use it.

Apparently, the package doesn't work. (Tried on Mac too)

Maybe on a web version it could run, With the Web Cryptography API.

huangapple
  • 本文由 发表于 2023年6月13日 01:58:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76459186.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定