Skip to content

Commit 58a1575

Browse files
committed
refactor: rename try_pubkey to pubkey and implement try_pubkey for better clarity and usability
1 parent a32af86 commit 58a1575

File tree

1 file changed

+22
-41
lines changed

1 file changed

+22
-41
lines changed

src/signer.rs

+22-41
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Into<SignerError> for GcpSignerError {
106106
}
107107

108108
impl solana_sdk::signer::Signer for GcpSigner {
109-
fn try_pubkey(&self) -> Result<solana_sdk::pubkey::Pubkey, solana_sdk::signer::SignerError> {
109+
fn try_pubkey(&self) -> Result<Pubkey, solana_sdk::signer::SignerError> {
110110
// Assuming you have a way to block on the future
111111
let pubkey = tokio::runtime::Runtime::new()
112112
.unwrap()
@@ -123,7 +123,7 @@ impl solana_sdk::signer::Signer for GcpSigner {
123123

124124
let der_bytes = base64::engine::general_purpose::STANDARD
125125
.decode(clean_b64)
126-
.unwrap();
126+
.map_err(|e| SignerError::Custom(e.to_string()))?;
127127

128128
Ok(Pubkey::from_str_const(
129129
std::str::from_utf8(&der_bytes).unwrap(),
@@ -196,45 +196,26 @@ mod test {
196196
.unwrap();
197197
let key_name = "projects/naturalselectionlabs/locations/us/keyRings/solana/cryptoKeys/solana/cryptoKeyVersions/1";
198198
let resp = request_get_pubkey(&client, key_name).await.unwrap();
199-
println!("resp: {:?}", resp);
200-
// assert_eq!(resp, PublicKey::default());
199+
200+
assert_eq!(resp.pem, String::from("-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAHDvdzUyFFG3pdn0ldkbPD81WliidLKqBHxfAt/3FbkU=\n-----END PUBLIC KEY-----\n"));
201+
assert_eq!(resp.name, key_name);
201202
}
202203

203-
// #[test]
204-
// fn test_key_specifier() {
205-
// let keyring = GcpKeyRingRef::new("test", "global", "test");
206-
// let key_specifier = KeySpecifier::new(keyring, "test", 1);
207-
// assert_eq!(
208-
// key_specifier.0,
209-
// "projects/test/locations/global/keyRings/test/cryptoKeys/test/cryptoKeyVersions/1"
210-
// );
211-
// }
212-
213-
// #[test]
214-
// fn test_gcp_keyring_ref() {
215-
// let keyring = GcpKeyRingRef::new("test", "global", "test");
216-
// assert_eq!(keyring.google_project_id, "test");
217-
// assert_eq!(keyring.location, "global");
218-
// assert_eq!(keyring.name, "test");
219-
// }
220-
221-
// #[test]
222-
// fn test_gcp_signer_debug() {
223-
// let client = Client::new().unwrap();
224-
// let key_specifier =
225-
// KeySpecifier::new(GcpKeyRingRef::new("test", "global", "test"), "test", 1);
226-
// let signer = GcpSigner::new(client, key_specifier).unwrap();
227-
// assert_eq!(
228-
// format!("{:?}", signer),
229-
// "GcpSigner { key_name: \"projects/test/locations/global/keyRings/test/cryptoKeys/test/cryptoKeyVersions/1\", address: \"\" }"
230-
// );
231-
// }
232-
233-
// #[test]
234-
// fn test_gcp_keyring_ref_new() {
235-
// let keyring = GcpKeyRingRef::new("test", "global", "test");
236-
// assert_eq!(keyring.google_project_id, "test");
237-
// assert_eq!(keyring.location, "global");
238-
// assert_eq!(keyring.name, "test");
239-
// }
204+
#[test]
205+
fn test_key_specifier() {
206+
let keyring = GcpKeyRingRef::new("test", "global", "test");
207+
let key_specifier = KeySpecifier::new(keyring, "test", 1);
208+
assert_eq!(
209+
key_specifier.0,
210+
"projects/test/locations/global/keyRings/test/cryptoKeys/test/cryptoKeyVersions/1"
211+
);
212+
}
213+
214+
#[test]
215+
fn test_gcp_keyring_ref() {
216+
let keyring = GcpKeyRingRef::new("test", "global", "test");
217+
assert_eq!(keyring.google_project_id, "test");
218+
assert_eq!(keyring.location, "global");
219+
assert_eq!(keyring.name, "test");
220+
}
240221
}

0 commit comments

Comments
 (0)