From 9a3684c22159ef78c7ba746ce38204e0d4589f43 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Thu, 9 Jul 2020 10:59:09 +0200 Subject: [PATCH] init from concrete key type (#252) --- libp2p/crypto/crypto.nim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libp2p/crypto/crypto.nim b/libp2p/crypto/crypto.nim index 66fe81c..78b7dd5 100644 --- a/libp2p/crypto/crypto.nim +++ b/libp2p/crypto/crypto.nim @@ -374,6 +374,24 @@ proc init*(t: typedesc[PrivateKey], data: string): CryptoResult[PrivateKey] = except ValueError: err(KeyError) +proc init*(t: typedesc[PrivateKey], key: rsa.RsaPrivateKey): PrivateKey = + PrivateKey(scheme: RSA, rsakey: key) +proc init*(t: typedesc[PrivateKey], key: EdPrivateKey): PrivateKey = + PrivateKey(scheme: Ed25519, edkey: key) +proc init*(t: typedesc[PrivateKey], key: SkPrivateKey): PrivateKey = + PrivateKey(scheme: Secp256k1, skkey: key) +proc init*(t: typedesc[PrivateKey], key: ecnist.EcPrivateKey): PrivateKey = + PrivateKey(scheme: ECDSA, eckey: key) + +proc init*(t: typedesc[PublicKey], key: rsa.RsaPublicKey): PublicKey = + PublicKey(scheme: RSA, rsakey: key) +proc init*(t: typedesc[PublicKey], key: EdPublicKey): PublicKey = + PublicKey(scheme: Ed25519, edkey: key) +proc init*(t: typedesc[PublicKey], key: SkPublicKey): PublicKey = + PublicKey(scheme: Secp256k1, skkey: key) +proc init*(t: typedesc[PublicKey], key: ecnist.EcPublicKey): PublicKey = + PublicKey(scheme: ECDSA, eckey: key) + proc init*(t: typedesc[PublicKey], data: string): CryptoResult[PublicKey] = ## Create new public key from libp2p's protobuf serialized hexadecimal string ## form.