AuthSession non empty vec part 2 (#1543)

This commit is contained in:
MinhPhan8803 2023-04-17 19:19:52 -05:00 committed by GitHub
parent fb337ecb54
commit 3e860feb13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -698,7 +698,7 @@ impl CredHandler {
/// "InProgress", "Success" or "Denied". From there the CredHandler /// "InProgress", "Success" or "Denied". From there the CredHandler
/// is interacted with until we move to either "Success" or "Denied". /// is interacted with until we move to either "Success" or "Denied".
enum AuthSessionState { enum AuthSessionState {
Init(Vec<CredHandler>), Init(NonEmpty<CredHandler>),
// Stop! Don't make this a vec - make the credhandler able to hold multiple // Stop! Don't make this a vec - make the credhandler able to hold multiple
// internal copies of it's type and check against them all. // internal copies of it's type and check against them all.
// //
@ -757,7 +757,7 @@ impl AuthSession {
// based on the anonymous ... in theory this could be cleaner // based on the anonymous ... in theory this could be cleaner
// and interact with the account more? // and interact with the account more?
if account.is_anonymous() { if account.is_anonymous() {
AuthSessionState::Init(vec![CredHandler::Anonymous { AuthSessionState::Init(nonempty![CredHandler::Anonymous {
cred_id: account.uuid, cred_id: account.uuid,
}]) }])
} else { } else {
@ -780,11 +780,11 @@ impl AuthSession {
handlers.push(ch); handlers.push(ch);
}; };
if handlers.is_empty() { if let Some(non_empty_handlers) = NonEmpty::collect(handlers.into_iter()) {
AuthSessionState::Init(non_empty_handlers)
} else {
security_info!("account has no available credentials"); security_info!("account has no available credentials");
AuthSessionState::Denied("invalid credential state") AuthSessionState::Denied("invalid credential state")
} else {
AuthSessionState::Init(handlers)
} }
} }
} else { } else {