pub struct SshSig { /* private fields */ }
Expand description
sshsig
provides a general-purpose signature format based on SSH keys and
wire formats.
These signatures can be produced using ssh-keygen -Y sign
. They’re
encoded as PEM and begin with the following:
-----BEGIN SSH SIGNATURE-----
See PROTOCOL.sshsig for more information.
Implementations
sourceimpl SshSig
impl SshSig
sourcepub fn new(
public_key: KeyData,
namespace: impl Into<String>,
hash_alg: HashAlg,
signature: Signature
) -> Result<Self>
pub fn new(
public_key: KeyData,
namespace: impl Into<String>,
hash_alg: HashAlg,
signature: Signature
) -> Result<Self>
Create a new signature with the given public key, namespace, hash algorithm, and signature.
sourcepub fn from_pem(pem: impl AsRef<[u8]>) -> Result<Self>
pub fn from_pem(pem: impl AsRef<[u8]>) -> Result<Self>
Decode signature from PEM which begins with the following:
-----BEGIN SSH SIGNATURE-----
sourcepub fn to_pem(&self, line_ending: LineEnding) -> Result<String>
pub fn to_pem(&self, line_ending: LineEnding) -> Result<String>
Encode signature as PEM which begins with the following:
-----BEGIN SSH SIGNATURE-----
sourcepub fn sign<S: SigningKey>(
signing_key: &S,
namespace: &str,
hash_alg: HashAlg,
msg: &[u8]
) -> Result<Self>
pub fn sign<S: SigningKey>(
signing_key: &S,
namespace: &str,
hash_alg: HashAlg,
msg: &[u8]
) -> Result<Self>
Sign the given message with the provided signing key.
sourcepub fn signed_data(
namespace: &str,
hash_alg: HashAlg,
msg: &[u8]
) -> Result<Vec<u8>>
pub fn signed_data(
namespace: &str,
hash_alg: HashAlg,
msg: &[u8]
) -> Result<Vec<u8>>
Get the raw message over which the signature for a given message needs to be computed.
This is a low-level function intended for uses cases which can’t be
expressed using SshSig::sign
, such as if the SigningKey
trait
can’t be used for some reason.
Once a Signature
has been computed over the returned byte vector,
SshSig::new
can be used to construct the final signature.
sourcepub fn version(&self) -> u32
pub fn version(&self) -> u32
Get version number for this signature.
Verifiers MUST reject signatures with versions greater than those they support.
sourcepub fn public_key(&self) -> &KeyData
pub fn public_key(&self) -> &KeyData
Get public key which corresponds to the signing key that produced this signature.
sourcepub fn namespace(&self) -> &str
pub fn namespace(&self) -> &str
Get the namespace (i.e. domain identifier) for this signature.
The purpose of the namespace value is to specify a unambiguous interpretation domain for the signature, e.g. file signing. This prevents cross-protocol attacks caused by signatures intended for one intended domain being accepted in another. The namespace value MUST NOT be the empty string.
sourcepub fn reserved(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn reserved(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Get reserved data associated with this signature. Typically empty.
The reserved value is present to encode future information (e.g. tags) into the signature. Implementations should ignore the reserved field if it is not empty.
sourcepub fn hash_alg(&self) -> HashAlg
pub fn hash_alg(&self) -> HashAlg
Get the hash algorithm used to produce this signature.
Data to be signed is first hashed with the specified hash_alg
.
This is done to limit the amount of data presented to the signature
operation, which may be of concern if the signing key is held in limited
or slow hardware or on a remote ssh-agent. The supported hash algorithms
are “sha256” and “sha512”.
Trait Implementations
sourceimpl Encode for SshSig
impl Encode for SshSig
sourcefn encoded_len(&self) -> Result<usize>
fn encoded_len(&self) -> Result<usize>
sourcefn encode(&self, writer: &mut impl Writer) -> Result<()>
fn encode(&self, writer: &mut impl Writer) -> Result<()>
Writer
.sourcefn encoded_len_prefixed(&self) -> Result<usize, Self::Error>
fn encoded_len_prefixed(&self) -> Result<usize, Self::Error>
uint32
length prefix. Read more