toPublicKey method
PublicKey?
toPublicKey()
Implementation
PublicKey? toPublicKey() {
switch (kty) {
case 'EC':
final type = const <String, KeyPairType>{
'P-256': KeyPairType.p256,
'P-384': KeyPairType.p384,
'P-521': KeyPairType.p521,
}[crv];
if (type == null) {
throw StateError('Unsupported "crv": "$crv"');
}
return EcPublicKey(
x: List<int>.unmodifiable(x ?? const <int>[]),
y: List<int>.unmodifiable(y ?? const <int>[]),
type: type,
);
case 'OCP':
final type = const <String, KeyPairType>{
'Ed25519': KeyPairType.ed25519,
'X25519': KeyPairType.x25519,
}[crv];
if (type == null) {
throw StateError('Unsupported "crv": "$crv"');
}
return SimplePublicKey(
List<int>.unmodifiable(x ?? const <int>[]),
type: type,
);
case 'RSA':
return RsaPublicKey(
e: List<int>.unmodifiable(e ?? const <int>[]),
n: List<int>.unmodifiable(n ?? const <int>[]),
);
}
return null;
}