rfc6238Seed function

Uint8List rfc6238Seed(
  1. OtpAlgorithm algorithm
)

RFC 6238 Appendix B seed for algorithm. The seed length differs per algorithm (20/32/64 bytes); reusing the 20-byte seed is the most common implementation bug. Test data only.

Implementation

Uint8List rfc6238Seed(OtpAlgorithm algorithm) {
  const base = '1234567890';
  final length = switch (algorithm) {
    OtpAlgorithm.sha1 => 20,
    OtpAlgorithm.sha256 => 32,
    OtpAlgorithm.sha512 => 64,
  };
  return Uint8List.fromList(
    List<int>.generate(length, (i) => base.codeUnitAt(i % 10)),
  );
}