Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TokenChallenge type fix #32

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/auth/authenticate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,37 @@ impl TokenChallenge {
}
}

/// Returns the token type.
#[must_use]
pub const fn token_type(&self) -> TokenType {
self.token_type
}

/// Returns the issuer name.
#[must_use]
pub fn issuer_name(&self) -> String {
String::from_utf8_lossy(self.issuer_name.as_slice()).to_string()
}

/// Returns the redemption context.
#[must_use]
pub fn redemption_context(&self) -> Option<RedemptionContext> {
if self.redemption_context.is_empty() {
None
} else {
Some(self.redemption_context.as_slice().try_into().unwrap())
}
}

/// Returns the origin info.
#[must_use]
pub fn origin_info(&self) -> Vec<String> {
String::from_utf8_lossy(self.origin_info.as_slice())
.split(',')
.map(|s| s.to_string())
.collect()
}

/// Serializes the `TokenChallenge`.
///
/// # Errors
Expand Down
8 changes: 7 additions & 1 deletion tests/kat_batched_ristretto255.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ async fn evaluate_kat(list: Vec<BatchedTokenTestVector>) {
.map(|blind| Ristretto255::deserialize_scalar(&blind.0).unwrap())
.collect();

// KAT: Check token challenge type
assert_eq!(
token_challenge.token_type(),
privacypass::TokenType::BatchedTokenRistretto255
);

// Client: Prepare a TokenRequest after having received a challenge
let (token_request, token_states) = client
.issue_token_request_with_params(&token_challenge, nonces, blinds)
Expand Down Expand Up @@ -183,7 +189,7 @@ async fn write_kat_batched_token_ristretto255() {
};

let kat_token_challenge = TokenChallenge::new(
privacypass::TokenType::BatchedTokenP384,
privacypass::TokenType::BatchedTokenRistretto255,
"Issuer Name",
redemption_context,
&["a".to_string(), "b".to_string(), "c".to_string()],
Expand Down
6 changes: 6 additions & 0 deletions tests/kat_batched_rp384.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ async fn evaluate_kat(list: Vec<BatchedTokenTestVector>) {
.map(|blind| NistP384::deserialize_scalar(&blind.0).unwrap())
.collect();

// KAT: Check token challenge type
assert_eq!(
token_challenge.token_type(),
privacypass::TokenType::BatchedTokenP384
);

// Client: Prepare a TokenRequest after having received a challenge
let (token_request, token_states) = client
.issue_token_request_with_params(&token_challenge, nonces, blinds)
Expand Down
6 changes: 6 additions & 0 deletions tests/kat_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ async fn evaluate_kat(list: Vec<PrivateTokenTestVector>) {
.issue_token_request_with_params(&token_challenge, nonce, blind)
.unwrap();

// KAT: Check token challenge type
assert_eq!(
token_challenge.token_type(),
privacypass::TokenType::PrivateToken
);

// KAT: Check token request
assert_eq!(
token_request.tls_serialize_detached().unwrap(),
Expand Down
6 changes: 6 additions & 0 deletions tests/kat_public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ async fn evaluate_kat(list: Vec<PublicTokenTestVector>) {
TokenChallenge::deserialize(vector.token_challenge.as_slice()).unwrap();
let challenge_digest: [u8; 32] = token_challenge.digest().unwrap();

// KAT: Check token challenge type
assert_eq!(
token_challenge.token_type(),
privacypass::TokenType::PublicToken
);

let (token_request, token_state) = client
.issue_token_request(det_rng, token_challenge)
.unwrap();
Expand Down
Loading
Loading