Skip to content

Commit

Permalink
add gpg EdDSA to jwk
Browse files Browse the repository at this point in the history
  • Loading branch information
fairingrey committed Jan 11, 2022
1 parent 5c5bd96 commit 4970859
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions did-webkey/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use ssi::did::{DIDMethod, Document, VerificationMethod, VerificationMethodMap, D
use ssi::did_resolve::{
DIDResolver, DocumentMetadata, ResolutionInputMetadata, ResolutionMetadata, ERROR_INVALID_DID,
};
use ssi::gpg::gpg_pkk_to_jwk;
use ssi::ssh::ssh_pkk_to_jwk;

// For testing, enable handling requests at localhost.
Expand Down
13 changes: 11 additions & 2 deletions src/gpg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::jwk::{Params as JWKParams, JWK};
use crate::jwk::{Base64urlUInt, Params as JWKParams, JWK};
use openpgp::{
crypto::mpi::PublicKey,
packet::{
Expand Down Expand Up @@ -29,7 +29,9 @@ pub fn gpg_pkk_to_jwk<P: KeyParts, R: KeyRole>(pkk: &Key<P, R>) -> Result<JWK, G
// https://datatracker.ietf.org/doc/html/rfc4253#section-6.6
if let Key::V4(key) = pkk {
match key.pk_algo() {
PublicKeyAlgorithm::RSAEncryptSign | PublicKeyAlgorithm::ECDSA => match key.mpis() {
PublicKeyAlgorithm::RSAEncryptSign
| PublicKeyAlgorithm::ECDSA
| PublicKeyAlgorithm::EdDSA => match key.mpis() {
PublicKey::RSA { e, n } => Ok(JWK::from(JWKParams::RSA(
crate::jwk::RSAParams::new_public(e.value(), n.value()),
))),
Expand All @@ -48,6 +50,13 @@ pub fn gpg_pkk_to_jwk<P: KeyParts, R: KeyRole>(pkk: &Key<P, R>) -> Result<JWK, G
Err(GpgKeyToJWKError::UnsupportedEcdsaKey(curve.to_string()))
}
}
PublicKey::EdDSA { curve, q } => {
Ok(JWK::from(JWKParams::OKP(crate::jwk::OctetParams {
curve: "Ed25519".to_string(),
public_key: Base64urlUInt(q.value().to_vec()),
private_key: None,
})))
}
_ => panic!("Something went wrong"),
},
_ => Err(GpgKeyToJWKError::UnsupportedGpgPkAlgorithm),
Expand Down

0 comments on commit 4970859

Please sign in to comment.