couchbase_core/
auth_mechanism.rs1use crate::error::Error;
20use crate::memdx;
21
22#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
23pub enum AuthMechanism {
24 Plain,
25 ScramSha1,
26 ScramSha256,
27 ScramSha512,
28 OAuthBearer,
29}
30
31impl From<AuthMechanism> for Vec<u8> {
32 fn from(value: AuthMechanism) -> Vec<u8> {
33 let txt = match value {
34 AuthMechanism::Plain => "PLAIN",
35 AuthMechanism::ScramSha1 => "SCRAM-SHA1",
36 AuthMechanism::ScramSha256 => "SCRAM-SHA256",
37 AuthMechanism::ScramSha512 => "SCRAM-SHA512",
38 AuthMechanism::OAuthBearer => "OAUTHBEARER",
39 };
40
41 txt.into()
42 }
43}
44
45impl TryFrom<&str> for AuthMechanism {
46 type Error = Error;
47
48 fn try_from(value: &str) -> Result<Self, Self::Error> {
49 let mech = match value {
50 "PLAIN" => AuthMechanism::Plain,
51 "SCRAM-SHA1" => AuthMechanism::ScramSha1,
52 "SCRAM-SHA256" => AuthMechanism::ScramSha256,
53 "SCRAM-SHA512" => AuthMechanism::ScramSha512,
54 "OAUTHBEARER" => AuthMechanism::OAuthBearer,
55 _ => {
56 return Err(Error::new_invalid_argument_error(
57 format!("unsupported auth mechanism {value}"),
58 None,
59 ));
60 }
61 };
62
63 Ok(mech)
64 }
65}
66
67impl From<AuthMechanism> for memdx::auth_mechanism::AuthMechanism {
68 fn from(value: AuthMechanism) -> Self {
69 match value {
70 AuthMechanism::Plain => memdx::auth_mechanism::AuthMechanism::Plain,
71 AuthMechanism::ScramSha1 => memdx::auth_mechanism::AuthMechanism::ScramSha1,
72 AuthMechanism::ScramSha256 => memdx::auth_mechanism::AuthMechanism::ScramSha256,
73 AuthMechanism::ScramSha512 => memdx::auth_mechanism::AuthMechanism::ScramSha512,
74 AuthMechanism::OAuthBearer => memdx::auth_mechanism::AuthMechanism::OAuthBearer,
75 }
76 }
77}