TomSecretsUnlockBundle.decode constructor
Reads the plaintext bytes (encode's form).
Implementation
factory TomSecretsUnlockBundle.decode(List<int> bytes) {
final Object? json;
try {
json = jsonDecode(utf8.decode(bytes));
} on FormatException {
throw const TomSecretsBundleException('no bundle');
}
if (json is! Map || json['v'] != 1) {
throw const TomSecretsBundleException('no bundle of version 1');
}
final composite = json['compositeKey'];
final outer = json['outerKey'];
if (composite is! String || (outer != null && outer is! String)) {
throw const TomSecretsBundleException('no bundle');
}
final Uint8List key;
try {
key = base64.decode(composite);
} on FormatException {
throw const TomSecretsBundleException('no composite key');
}
try {
return TomSecretsUnlockBundle(
compositeKey: key,
outerKey: outer as String?,
);
} finally {
key.fillRange(0, key.length, 0);
}
}