Skip to content

Commit e3e51a8

Browse files
committed
Fix build by removing code that does not compile
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
1 parent 5d5fb38 commit e3e51a8

File tree

10 files changed

+25
-27
lines changed

10 files changed

+25
-27
lines changed

.justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fix:
8383
# try to fix rustc issues
8484
cargo fix --allow-staged
8585
# try to fix clippy issues
86-
cargo clippy --fix --allow-staged
86+
cargo clippy --fix --allow-staged --allow-dirty
8787

8888
# fmt must be last as clippy's changes may break formatting
8989
cargo +nightly fmt --all

examples/agent-socket-info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Session for AgentSocketInfo {
2727
async fn request_identities(&mut self) -> Result<Vec<Identity>, AgentError> {
2828
Ok(vec![Identity {
2929
// this is just a dummy key, the comment is important
30-
pubkey: KeyData::Ed25519(ssh_key::public::Ed25519PublicKey([0; 32])),
30+
pubkey: KeyData::Ed25519(ssh_key::public::Ed25519PublicKey([0; 32])).into(),
3131
comment: self.comment.clone(),
3232
}])
3333
}

examples/key-storage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl KeyStorage {
7474
#[crate::async_trait]
7575
impl Session for KeyStorage {
7676
async fn sign(&mut self, sign_request: SignRequest) -> Result<Signature, AgentError> {
77-
let pubkey: PublicKey = sign_request.pubkey.clone().into();
77+
let pubkey: PublicKey = sign_request.pubkey.key_data().clone().into();
7878

7979
if let Some(identity) = self.identity_from_pubkey(&pubkey) {
8080
match identity.privkey.key_data() {
@@ -113,7 +113,7 @@ impl Session for KeyStorage {
113113
let mut identities = vec![];
114114
for identity in self.identities.lock().unwrap().iter() {
115115
identities.push(message::Identity {
116-
pubkey: identity.pubkey.key_data().clone(),
116+
pubkey: identity.pubkey.key_data().clone().into(),
117117
comment: identity.comment.clone(),
118118
})
119119
}

examples/openpgp-card-agent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl CardSession {
7171
if let AlgorithmAttributes::Ecc(ecc) = e.algo() {
7272
if ecc.ecc_type() == EccType::EdDSA {
7373
let pubkey = KeyData::Ed25519(Ed25519PublicKey(e.data().try_into()?));
74-
if pubkey == request.pubkey {
74+
if pubkey == *request.pubkey.key_data() {
7575
let pin = self.pwds.get(&ident).await;
7676
return if let Some(pin) = pin {
7777
let str = pin.expose_secret().as_bytes().to_vec();

examples/pgp-wrapper.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl SecretKeyTrait for WrappedKey {
295295
.block_on(async {
296296
let mut client = self.client.lock().await;
297297
let result = client.sign(SignRequest {
298-
pubkey: self.pubkey.clone(),
298+
pubkey: self.pubkey.clone().into(),
299299
data: data.to_vec(),
300300
flags: 0,
301301
});
@@ -454,9 +454,7 @@ fn main() -> testresult::TestResult {
454454
pgp::packet::write_packet(&mut std::io::stdout(), &signature)?;
455455
}
456456
Args::Decrypt => {
457-
let CertKeyData::Key(pubkey) = decrypt_ids[0].pubkey else {
458-
panic!("Only pubkeys are supported");
459-
};
457+
let pubkey = decrypt_ids[0].pubkey.key_data();
460458
let decryptor = WrappedKey::new(pubkey.clone(), client, KeyRole::Decryption);
461459
let message = Message::from_bytes(std::io::stdin())?;
462460

src/proto/message/cert_key_data.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
use std::str::FromStr as _;
1+
use ssh_encoding::{Decode, Encode, Reader};
2+
use ssh_key::{public::KeyData, Certificate};
23

3-
use ssh_encoding::{CheckedSum as _, Decode, Encode, Reader};
4-
use ssh_key::{public::KeyData, Algorithm, Certificate, PublicKey};
5-
6-
use crate::proto::{Error, Result};
4+
use crate::proto::Error;
75

86
#[derive(Debug, PartialEq, Eq, Clone)]
7+
/// Represents a public credential.
98
pub enum CertKeyData {
9+
/// Plain public key.
1010
Key(KeyData),
11+
/// Signed public key.
1112
Cert(Certificate),
1213
}
1314

15+
impl CertKeyData {
16+
/// Returns a reference to the [KeyData].
17+
pub fn key_data(&self) -> &KeyData {
18+
match self {
19+
Self::Key(key) => key,
20+
Self::Cert(cert) => cert.public_key(),
21+
}
22+
}
23+
}
24+
1425
impl Decode for CertKeyData {
1526
type Error = Error;
1627

1728
fn decode(reader: &mut impl Reader) -> core::result::Result<Self, Self::Error> {
18-
let alg = String::decode(reader)?;
19-
let cert_alg = Algorithm::new_certificate(&alg);
20-
21-
if let Ok(algorithm) = cert_alg {
22-
let certificate = Certificate::decode_as(algorithm.clone(), reader)?;
23-
Ok(Self::Cert(certificate))
24-
} else {
25-
let algorithm = Algorithm::from_str(&alg).map_err(ssh_encoding::Error::from)?;
26-
let pubkey = KeyData::decode_as(reader, algorithm)?;
27-
Ok(Self::Key(pubkey))
28-
}
29+
// TODO: implement parsing certificates
30+
Ok(Self::Key(KeyData::decode(reader)?))
2931
}
3032
}
3133

src/proto/message/identity.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Data returned to the client when listing keys.
22
33
use ssh_encoding::{self, CheckedSum, Decode, Encode, Reader, Writer};
4-
use ssh_key::public::KeyData;
54

65
use super::cert_key_data::CertKeyData;
76
use crate::proto::{Error, Result};

src/proto/message/sign.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Signature request with data to be signed with a key in an agent.
22
33
use ssh_encoding::{self, CheckedSum, Decode, Encode, Reader, Writer};
4-
use ssh_key::public::KeyData;
54

65
use super::cert_key_data::CertKeyData;
76
use crate::proto::{Error, Result};

0 commit comments

Comments
 (0)