parseOpenSshPublicKey static method

({String comment, Uint8List publicKeyRaw}) parseOpenSshPublicKey(
  1. String line
)

Implementation

static ({Uint8List publicKeyRaw, String comment}) parseOpenSshPublicKey(
  String line,
) {
  final trimmed = line.trim();
  final parts = trimmed.split(RegExp(r'\s+'));
  if (parts.length < 2 || parts.first != 'ssh-ed25519') {
    throw ArgumentError('Linha de chave publica OpenSSH invalida');
  }
  final blob = base64.decode(parts[1]);
  var off = 0;
  final keyType = _readSshString(blob, off);
  off = keyType.nextOffset;
  if (utf8.decode(keyType.value) != 'ssh-ed25519') {
    throw ArgumentError('Tipo de chave OpenSSH nao suportado');
  }
  final pub = _readSshString(blob, off);
  if (pub.value.length != 32) {
    throw ArgumentError('Chave publica Ed25519 invalida');
  }
  final comment = parts.length > 2 ? parts.sublist(2).join(' ') : '';
  return (publicKeyRaw: Uint8List.fromList(pub.value), comment: comment);
}