mirror of
https://github.com/danog/tergent.git
synced 2024-12-02 09:27:57 +01:00
Remove redundant code for key name building
This commit is contained in:
parent
489593eb7a
commit
38bded3682
@ -24,51 +24,37 @@ impl<'a> SignRequest<'a> {
|
|||||||
&self.data
|
&self.data
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: these two functions below are too similiar...
|
/// Returns the tuple of keystore name and ssh name for this key.
|
||||||
|
fn name(&self) -> (&'static str, &'static str) {
|
||||||
/// Returns the name to be used when communicating with the
|
|
||||||
/// Android keystore.
|
|
||||||
pub fn keystore_name(&self) -> &'static str {
|
|
||||||
// TODO: handle invalid flags gracefully
|
// TODO: handle invalid flags gracefully
|
||||||
match self.key.algorithm {
|
match self.key.algorithm {
|
||||||
Algorithm::Rsa => {
|
Algorithm::Rsa => {
|
||||||
match self.flags {
|
match self.flags {
|
||||||
0 => "SHA1withRSA",
|
0 => ("SHA1withRSA", "ssh-rsa"),
|
||||||
SSH_AGENT_RSA_SHA2_256 => "SHA256withRSA",
|
SSH_AGENT_RSA_SHA2_256 => ("SHA256withRSA", "rsa-sha2-256"),
|
||||||
SSH_AGENT_RSA_SHA2_512 => "SHA512withRSA",
|
SSH_AGENT_RSA_SHA2_512 => ("SHA512withRSA", "rsa-sha2-512"),
|
||||||
f => panic!("Unknown flag {}", f),
|
f => panic!("Unknown flag {}", f),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Algorithm::Ec(ref curve) => {
|
Algorithm::Ec(ref curve) => {
|
||||||
match curve {
|
match curve {
|
||||||
Curve::P256 => "SHA256withECDSA",
|
Curve::P256 => ("SHA256withECDSA", "ecdsa-sha2-nistp256"),
|
||||||
Curve::P384 => "SHA386withECDSA",
|
Curve::P384 => ("SHA386withECDSA", "ecdsa-sha2-nistp384"),
|
||||||
Curve::P521 => "SHA512withECDSA",
|
Curve::P521 => ("SHA512withECDSA", "ecdsa-sha2-nistp521"),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the name to be used when communicating with the
|
||||||
|
/// Android keystore.
|
||||||
|
pub fn keystore_name(&self) -> &'static str {
|
||||||
|
self.name().0
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the name to be used when communicating with an
|
/// Returns the name to be used when communicating with an
|
||||||
/// ssh-agent client.
|
/// ssh-agent client.
|
||||||
pub fn ssh_name(&self) -> &'static str {
|
pub fn ssh_name(&self) -> &'static str {
|
||||||
// TODO: handle invalid flags gracefully
|
self.name().1
|
||||||
match self.key.algorithm {
|
|
||||||
Algorithm::Rsa => {
|
|
||||||
match self.flags {
|
|
||||||
0 => "ssh-rsa",
|
|
||||||
SSH_AGENT_RSA_SHA2_256 => "rsa-sha2-256",
|
|
||||||
SSH_AGENT_RSA_SHA2_512 => "rsa-sha2-512",
|
|
||||||
f => panic!("Unknown flag {}", f),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Algorithm::Ec(ref curve) => {
|
|
||||||
match curve {
|
|
||||||
Curve::P256 => "ecdsa-sha2-nistp256",
|
|
||||||
Curve::P384 => "ecdsa-sha2-nistp384",
|
|
||||||
Curve::P521 => "ecdsa-sha2-nistp521",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user