Skip to content

Commit

Permalink
Merge branch 'tim/new_verif_method_oidc' into 'master'
Browse files Browse the repository at this point in the history
feat: Upgrade verif method with new OIDC provider fields (BREAKING)

See merge request TankerHQ/sdk-rust!171
  • Loading branch information
tux3 committed Sep 19, 2023
2 parents b34f598 + 6fab187 commit e538fe1
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/verification_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ pub enum VerificationMethod {
Passphrase,
VerificationKey,
#[allow(clippy::upper_case_acronyms)]
OIDCIDToken,
OIDCIDToken {
provider_id: String,
provider_display_name: String,
},
PhoneNumber(String),
PreverifiedEmail(String),
PreverifiedPhoneNumber(String),
Expand Down Expand Up @@ -46,28 +49,38 @@ impl VerificationMethod {
match ctype.into() {
CMethodType::Email => {
// SAFETY: If we get a valid Email verification method, the email is a valid string
let c_email = unsafe { CStr::from_ptr(method.value) };
let c_email = unsafe { CStr::from_ptr(method.value1) };
let email = c_email.to_str().unwrap().into();
Ok(VerificationMethod::Email(email))
}
CMethodType::Passphrase => Ok(VerificationMethod::Passphrase),
CMethodType::VerificationKey => Ok(VerificationMethod::VerificationKey),
CMethodType::OIDCIDToken => Ok(VerificationMethod::OIDCIDToken),
CMethodType::OIDCIDToken => {
// SAFETY: If we get a valid OIDC verification method, the values are valid strings
let c_prov_id = unsafe { CStr::from_ptr(method.value1) };
let provider_id = c_prov_id.to_str().unwrap().into();
let c_prov_name = unsafe { CStr::from_ptr(method.value2) };
let provider_display_name = c_prov_name.to_str().unwrap().into();
Ok(VerificationMethod::OIDCIDToken {
provider_id,
provider_display_name,
})
}
CMethodType::PhoneNumber => {
// SAFETY: If we get a valid PhoneNumber verification method, the number is a valid string
let c_phone_number = unsafe { CStr::from_ptr(method.value) };
let c_phone_number = unsafe { CStr::from_ptr(method.value1) };
let phone_number = c_phone_number.to_str().unwrap().into();
Ok(VerificationMethod::PhoneNumber(phone_number))
}
CMethodType::PreverifiedEmail => {
// SAFETY: If we get a valid Email verification method, the email is a valid string
let c_preverified_email = unsafe { CStr::from_ptr(method.value) };
let c_preverified_email = unsafe { CStr::from_ptr(method.value1) };
let preverified_email = c_preverified_email.to_str().unwrap().into();
Ok(VerificationMethod::PreverifiedEmail(preverified_email))
}
CMethodType::PreverifiedPhoneNumber => {
// SAFETY: If we get a valid PhoneNumber verification method, the number is a valid string
let c_preverified_phone_number = unsafe { CStr::from_ptr(method.value) };
let c_preverified_phone_number = unsafe { CStr::from_ptr(method.value1) };
let preverified_phone_number = c_preverified_phone_number.to_str().unwrap().into();
Ok(VerificationMethod::PreverifiedPhoneNumber(
preverified_phone_number,
Expand Down

0 comments on commit e538fe1

Please sign in to comment.