pub struct RsaKeyPairSigner<K, R, A>
where K: RsaKey, R: SecureRandom, A: Algorithm,
{ /* private fields */ }
Available on crate feature ring only.
Expand description

Wrapper for ::ring::signature::RsaKeyPair.

Examples

RS256 PKCS8

let private_key =
"-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDJ8SJJvYSWrKXI
B9aRtXQmYrDNpgfYm1aLTl0QusalIj44zaY2YWenFlVRTHvsZYBIP678RsOkHtPG
gvzBbqtIW525Mhvre6Gp6KWSPpWGk9dUulmDqbySisBc8Zo3kEExPIEBulaT17vb
PmA4ZoUYjjE6/S/c3QxfaH25cm+E9Ok50qfqNcR+VQUXz05YYSH/cmfJltfmnz4X
wEC6x5vyB+mpPYK3opPkas2IDt0/CM3tcW9We/JiBHv5BdNU1EytysRSgltHgMb5
BV7IhGHQkape2b3TVy+I8FFuJwgyfZ/yp+zXlcxJ4dauB6XbUK/XBCHcjjHL6yhm
5lnaL+nPAgMBAAECggEAbv/LIAs68PMvILcmOuspT9wZYMBtOaOQu3u0bfisLaKX
3vMy9Fsv9UiyVsCasULNc2kFzwc6jGCheVEQi2ZAYcJx/JTNge9v2gvVzn/2AoYK
6ziO8W8ABvCbcbsfUIFLRDwEkSWSZytCx+0OSJIZgHjQGKOIhnc+UMcHrEJ5h/N4
teVo/6JOJkvBJOKCIQKt8Y1tjmjX7cNjhYP5+1SgkwyDJqm2G0l2BRgttWvgDeQ2
ACibNYOIWj71Gmtup4gVqYwWxNgcIFkrz24dxe4yI53ieLHBk4bOJenJ+OeEKQjY
boN4lDqQgCiwjowe8B+vbSpvmHiTwsPm7ASpZN6eSQKBgQDirgvjnHL81rmrXqod
Msod/Yn4SD8Jc9TC3e1L8wh6LBSnj/SVdziUOo+NOHoJ9mcTDKjAAfDgmKHbAoKJ
RDP1BuHX0uyIkdC5AIoLkm9QAf3qKPNwrRMwKqWw0qbbiY6FAIbcKF/YFETjDB8V
CBVQGvuPJlsp8lipdv8/tlQkzQKBgQDkD/NgIRRmgO0sIxtSI5KwJfT6VyJc1NLm
jp25c9IfEWSZdzhywXN9qomKkCs34tBkexlKx01Oph7Jdepntry3sVu4m08QK9NC
Z97i++TYCCeIBZoLwolRPO8IFqAq803h3QCENDAZnP+Fl7Z7dgZa443Z9n3C/755
OVhSMWOpCwKBgQDMVR+aeTid+eE8PQUTdOkEx7tK97T7DFLJpct2HwmRN5MWyIkt
Al8aHv+vyS0ZNegMH+kty5IaovujtEt++N/tC9sg9Z0KLob7fSTy8Xktod4E6g0n
kJwvWwIotnp6gzDZa3QlmK9s1DiUgiSyjKrJnskMbQLYeQC7Ie1MvUp0MQKBgQCy
+1WsRqnE/D+mGPMzFlnjxhYpdcKxChFuAdUEm0H3QeYqjqcNYIbrw6/nv9c7J9UW
Vol1503jgHm+77yDoqUeoKF0EucMsOg+QFhq2PczF8s2c/b+bbDowaJyPZd7vbCM
pq3mEzMAlvbt+C+tWuYH5HgJ6+ms5JqudnO7JamqGwKBgGcDDTdxmOm4YX5G1wiE
Lafrn9dXK31D7quBNl2j6p3hV+vhIYitwSP/VbZgTG4q9CpuFD7TMn2wycKzFmFq
urcMnLLy5lKPBVegcd9144Z11WDzraFESvBRqfSWEVTTLXDBDo0XfHQPnCSpfPlN
4eEjZ7+NQEVHHG2ZVHFCcMBv
-----END PRIVATE KEY-----";

// Convert the PKCS8 PEM to DER
let private_key = convert_pkcs8_pem_to_der(private_key);

let private_key = ::ring::signature::RsaKeyPair::from_pkcs8(
  private_key.as_ref()
).unwrap();
let secure_random = ::ring::rand::SystemRandom::new();

let signer = min_jwt::sign::ring::RsaKeyPairSigner::with_rs256(
  private_key,
  secure_random
);
let jwt = min_jwt::encode_and_sign(header.as_bytes(), claims.as_bytes(), &signer)?;

Implementations§

source§

impl<K, R, A> RsaKeyPairSigner<K, R, A>
where K: RsaKey, R: SecureRandom, A: Algorithm,

source

pub fn into_inner(self) -> (K, R)

Returns the inner key and SecureRandom.

source§

impl<K, R> RsaKeyPairSigner<K, R, Rs256>
where K: RsaKey, R: SecureRandom,

source

pub fn with_rs256( key_pair: K, secure_random: R ) -> RsaKeyPairSigner<K, R, Rs256>

Signs header and claims parts with an RSA key.

Trait Implementations§

source§

impl<K, R, A> Debug for RsaKeyPairSigner<K, R, A>
where K: RsaKey + Debug, R: SecureRandom + Debug, A: Algorithm + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K, R, A> Signer for RsaKeyPairSigner<K, R, A>
where K: RsaKey, R: SecureRandom, A: Algorithm,

§

type Signature = <K as RsaKey>::Signature

Returned signature type which implmenets the Signature trait.
§

type Error = <K as RsaKey>::Error

Returns an error.
source§

fn sign(&self, bytes: &[u8]) -> Result<Self::Signature, Self::Error>

Returns a signature from a byte buffer. Read more

Auto Trait Implementations§

§

impl<K, R, A> RefUnwindSafe for RsaKeyPairSigner<K, R, A>

§

impl<K, R, A> Send for RsaKeyPairSigner<K, R, A>
where A: Send, K: Send, R: Send,

§

impl<K, R, A> Sync for RsaKeyPairSigner<K, R, A>
where A: Sync, K: Sync, R: Sync,

§

impl<K, R, A> Unpin for RsaKeyPairSigner<K, R, A>
where A: Unpin, K: Unpin, R: Unpin,

§

impl<K, R, A> UnwindSafe for RsaKeyPairSigner<K, R, A>
where A: UnwindSafe, K: UnwindSafe, R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V