OpenSSHKeyPairs.decode constructor
OpenSSHKeyPairs.decode(
- Uint8List keyBlob
Implementation
factory OpenSSHKeyPairs.decode(Uint8List keyBlob) {
final reader = SSHMessageReader(keyBlob);
final actualMagic = reader.readBytes(magic.length);
if (!actualMagic.equals(magic.codeUnits)) {
throw FormatException('Invalid magic: ${latin1.decode(actualMagic)}');
}
reader.readUint8(); // terminator of magic
final cipher = reader.readUtf8();
final kdfName = reader.readUtf8();
late final OpenSSHBcryptKdfOptions? kdfOptions;
final kdfOptionsBlock = reader.readString();
if (cipher == 'none') {
kdfOptions = null;
} else if (kdfName == 'bcrypt') {
kdfOptions = OpenSSHBcryptKdfOptions.decode(kdfOptionsBlock);
} else {
throw UnsupportedError('Unsupported key derivation function: $kdfName');
}
final keyCount = reader.readUint32();
final publicKeys = <Uint8List>[];
for (var i = 0; i < keyCount; i++) {
publicKeys.add(reader.readString());
}
final privateKeysBlob = reader.readString();
return OpenSSHKeyPairs(
cipherName: cipher,
kdfName: kdfName,
kdfOptions: kdfOptions,
publicKeys: publicKeys,
privateKeyBlob: privateKeysBlob,
);
}