Skip to content

Commit

Permalink
Merge pull request #11 from banyancomputer/vera/new-fingerprints
Browse files Browse the repository at this point in the history
feat: updated ApiTokens and added hex_fingerprint method
  • Loading branch information
organizedgrime authored Oct 25, 2023
2 parents 998fbeb + 0ada330 commit 0cd64a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/key_seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub fn pretty_fingerprint(fingerprint_bytes: &[u8]) -> String {
.join(":")
}

pub fn hex_fingerprint(fingerprint_bytes: &[u8]) -> String {
pretty_fingerprint(fingerprint_bytes).replace(':', "")
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
6 changes: 3 additions & 3 deletions src/key_seal/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::hex_fingerprint;
use crate::prelude::*;
use crate::pretty_fingerprint;
use async_trait::async_trait;
use jwt_simple::prelude::*;
use rand::{distributions::Alphanumeric, Rng};
Expand Down Expand Up @@ -298,7 +298,7 @@ impl ApiToken {
public_key: &EcPublicSignatureKey,
) -> Result<Self, TombCryptError> {
let key_bytes = public_key.export_bytes().await?;
let key_id = pretty_fingerprint(public_key.fingerprint().await?.as_slice());
let key_id = hex_fingerprint(public_key.fingerprint().await?.as_slice());
let decoding_key = ES384PublicKey::from_der(&key_bytes)
.map_err(TombCryptError::jwt_error)?
.with_key_id(&key_id);
Expand All @@ -320,7 +320,7 @@ impl ApiToken {
let pem_string = std::str::from_utf8(&pem_bytes).map_err(TombCryptError::invalid_utf8)?;
let encoding_key = ES384KeyPair::from_pem(pem_string)
.map_err(TombCryptError::jwt_error)?
.with_key_id(&pretty_fingerprint(
.with_key_id(&hex_fingerprint(
signing_key.fingerprint().await?.as_slice(),
));
let claims = &self.0;
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod key_seal;

pub use crate::key_seal::hex_fingerprint;
pub use crate::key_seal::pretty_fingerprint;

pub mod prelude {
Expand Down

0 comments on commit 0cd64a2

Please sign in to comment.