Skip to content

Commit

Permalink
Switch to RustCrypto and get successful roundtrip
Browse files Browse the repository at this point in the history
Switch to RustCrypto where possible (ECDH). Roundtrip is now successful.
  • Loading branch information
tgross35 committed Nov 10, 2023
1 parent 05e166c commit 8145bd9
Show file tree
Hide file tree
Showing 12 changed files with 819 additions and 295 deletions.
13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@ serde_json = { version = "1.0.108", features = ["preserve_order"] }
ureq = { version = "2.8.0", features = ["json"] }
sha1 = "0.10.6"
hex = "0.4.3"
p521 = { git = "https://github.com/RustCrypto/elliptic-curves.git" }
p256 = { git = "https://github.com/RustCrypto/elliptic-curves.git" }
k256 = { git = "https://github.com/RustCrypto/elliptic-curves.git", features = ["ecdh", "ecdsa", "jwk"] }
p256 = { git = "https://github.com/RustCrypto/elliptic-curves.git", features = ["ecdh", "ecdsa", "jwk"] }
p384 = { git = "https://github.com/RustCrypto/elliptic-curves.git", features = ["ecdh", "ecdsa", "jwk"] }
p521 = { git = "https://github.com/RustCrypto/elliptic-curves.git", features = ["ecdh", "jwk"] }
base64ct = { version = "1.6.0", features = ["alloc"] }
elliptic-curve = { version = "0.13.6", features = ["jwk"] }
primeorder = "0.13.3"
aead = "0.5.2"
concat-kdf = "0.1.0"

# vsss-rs = "2.7.1"

[features]
_backend = []

[dev-dependencies]
aes-gcm = "0.10.3"
24 changes: 0 additions & 24 deletions src/_decrypt.rs

This file was deleted.

137 changes: 0 additions & 137 deletions src/_encrypt.rs

This file was deleted.

34 changes: 29 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{fmt, io, str::Utf8Error};

use josekit::jwk::Jwk;

pub type Result<T, E = Error> = core::result::Result<T, E>;

#[derive(Debug)]
Expand All @@ -14,23 +16,39 @@ pub enum Error {
Base64(base64ct::Error),
Json(serde_json::Error),
Jose(josekit::JoseError),
VerifyKey,
KeyType(Box<str>),
VerifyKey,
InvalidPublicKey(Jwk),
EllipitcCurve(elliptic_curve::Error),
MissingPublicKey,
IdentityPointCreated,
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::VerifyKey => write!(f, "missing a key marked 'verify'"),
Self::KeyType(v) => write!(f, "unsupported key type {v}"),
Self::Server(e) => write!(f, "server error: {e}"),
Self::Algorithm(v, c) => write!(f, "invalid algorithm {v} for {c}"),
Error::IoError(e) => write!(f, "io error {e}"),
Error::MissingKeyOp(e) => write!(f, "no key operation {e}"),
Error::Json(e) => write!(f, "json serde error: {e}"),
Self::JsonMissingKey(v) => write!(f, "missing key {v}"),
Self::JsonKeyType(v) => write!(f, "invalid key type {v} in JSON"),
Self::Algorithm(v, c) => write!(f, "invalid algorithm {v} for {c}"),
_ => write!(f, ""),
Error::Utf8(e) => write!(f, "utf8 error {e}"),
Error::Base64(e) => write!(f, "base64 error {e}"),
Self::VerifyKey => write!(f, "missing a key marked 'verify'"),
Self::KeyType(v) => write!(f, "unsupported key type {v}"),
Error::Jose(e) => write!(f, "jose error {e}"),
Error::InvalidPublicKey(key) => write!(f, "invalid public key {key}"),
Error::EllipitcCurve(_) => write!(f, "elliptic curve cryptography"),
Error::MissingPublicKey => write!(f, "could not locate a key with the correct key ID"),
Error::IdentityPointCreated => write!(f, "math resulted an an identity key"),
}
}
}

impl std::error::Error for Error {}

impl From<ureq::Error> for Error {
fn from(value: ureq::Error) -> Self {
Error::Server(value.into())
Expand Down Expand Up @@ -66,3 +84,9 @@ impl From<josekit::JoseError> for Error {
Self::Jose(value)
}
}

impl From<elliptic_curve::Error> for Error {
fn from(value: elliptic_curve::Error) -> Self {
Self::EllipitcCurve(value)
}
}
Loading

0 comments on commit 8145bd9

Please sign in to comment.