oracle_nosql_rust_sdk/auth_common/
authentication_provider.rs

1//
2// Copyright (c) 2024, 2025 Oracle and/or its affiliates. All rights reserved.
3//
4// Licensed under the Universal Permissive License v 1.0 as shown at
5//  https://oss.oracle.com/licenses/upl/
6//
7use openssl::pkey::Private;
8use openssl::rsa::Rsa;
9use std::error::Error;
10use std::fmt::Debug;
11
12/// Trait defining an Authentication Provider
13pub trait AuthenticationProvider: Send + Sync + Debug + AuthenticationProviderClone {
14    /// Returns the Tenancy OCID associated with this AuthenticationProvider
15    fn tenancy_id(&self) -> &str;
16    /// Returns the User OCID associated with this AuthenticationProvider
17    fn user_id(&self) -> &str;
18    /// Returns the Fingerprint associated with the Private Key of this AuthenticationProvider
19    fn fingerprint(&self) -> &str;
20    /// Returns the Private Key associated with this AuthenticationProvider
21    fn private_key(&self) -> Result<Rsa<Private>, Box<dyn Error>>;
22    /// Returns the key id associated with this AuthenticationProvider to be used for signing requests
23    fn key_id(&self) -> String {
24        let key_id = format!(
25            "{}/{}/{}",
26            self.tenancy_id(),
27            self.user_id(),
28            self.fingerprint()
29        );
30        key_id
31    }
32    /// Returns the region-id associated with this AuthenticationProvider
33    fn region_id(&self) -> &str;
34}
35
36// This allows users of this library to clone a Box<dyn AuthenticationProvider>
37pub trait AuthenticationProviderClone {
38    fn clone_box(&self) -> Box<dyn AuthenticationProvider>;
39}
40
41impl<T> AuthenticationProviderClone for T
42where
43    T: 'static + AuthenticationProvider + Clone,
44{
45    fn clone_box(&self) -> Box<dyn AuthenticationProvider> {
46        Box::new(self.clone())
47    }
48}
49
50impl Clone for Box<dyn AuthenticationProvider> {
51    fn clone(&self) -> Box<dyn AuthenticationProvider> {
52        self.clone_box()
53    }
54}