pub struct SshSig { /* private fields */ }
alloc
only.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.
§Usage
See PrivateKey::sign
and PublicKey::verify
for usage information.
Implementations§
source§impl 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.
See also: PrivateKey::sign
.
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] ⓘ
pub fn reserved(&self) -> &[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”.
sourcepub fn signature_bytes(&self) -> &[u8] ⓘ
pub fn signature_bytes(&self) -> &[u8] ⓘ
Get the bytes which comprise the serialized signature.
Trait Implementations§
source§impl Encode for SshSig
impl Encode for SshSig
source§fn encoded_len(&self) -> Result<usize>
fn encoded_len(&self) -> Result<usize>
source§fn encode(&self, writer: &mut impl Writer) -> Result<()>
fn encode(&self, writer: &mut impl Writer) -> Result<()>
Writer
.source§fn encoded_len_prefixed(&self) -> Result<usize, Error>
fn encoded_len_prefixed(&self) -> Result<usize, Error>
uint32
length prefix.source§fn encode_prefixed(&self, writer: &mut impl Writer) -> Result<(), Error>
fn encode_prefixed(&self, writer: &mut impl Writer) -> Result<(), Error>
uint32
length prefix
set to Encode::encoded_len
.impl Eq for SshSig
impl StructuralPartialEq for SshSig
Auto Trait Implementations§
impl Freeze for SshSig
impl RefUnwindSafe for SshSig
impl Send for SshSig
impl Sync for SshSig
impl Unpin for SshSig
impl UnwindSafe for SshSig
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> EncodePem for T
impl<T> EncodePem for T
source§fn encode_pem<'o>(
&self,
line_ending: LineEnding,
out: &'o mut [u8],
) -> Result<&'o str, Error>
fn encode_pem<'o>( &self, line_ending: LineEnding, out: &'o mut [u8], ) -> Result<&'o str, Error>
Encode
trait, writing the resulting PEM
document into the provided out
buffer.source§fn encode_pem_string(&self, line_ending: LineEnding) -> Result<String, Error>
fn encode_pem_string(&self, line_ending: LineEnding) -> Result<String, Error>
alloc
only.