pub fn sign<ExtraClaims: Serialize>(
    claims: &mut HeaderAndClaims<ExtraClaims>,
    k: &dyn SigningKey,
) -> Result<String> {
    claims.header.alg = k.alg().into();
    if let Some(kid) = k.kid() {
        claims.set_kid(kid);
    }

    let mut w = base64::write::EncoderStringWriter::new(url_safe_trailing_bits());
    serde_json::to_writer(&mut w, &claims.header)?;

    let mut buf = w.into_inner();
    buf.push('.');
    let mut w = base64::write::EncoderStringWriter::from(buf, url_safe_trailing_bits());

    serde_json::to_writer(&mut w, &claims.claims)?;
    let mut buf = w.into_inner();

    let sig = k.sign(buf.as_bytes())?;

    buf.push('.');

    let mut w = base64::write::EncoderStringWriter::from(buf, url_safe_trailing_bits());
    w.write_all(&sig)?;
    Ok(w.into_inner())
}
/// Encode and sign this header and claims with the signing key.
///
/// The `alg` field in header is automatically set. The `kid` claim is
/// automatically set if the key has an id.
///
/// Returns a signed JWT.
Encode and sign this header and claims with the signing key.
The `alg` field in header is automatically set. The `kid` claim is
automatically set if the key has an id.

Returns a signed JWT.
Encode and sign this header and claims with the signing key . The ` alg ` field in header is automatically set . The ` kid ` claim is automatically set if the key has an id . Returns a signed JWT .
pub fn sign<ExtraClaims: Serialize>(
    claims: &mut HeaderAndClaims<ExtraClaims>,
    k: &dyn SigningKey,
) -> Result<String> {
    claims.header.alg = k.alg().into();
    if let Some(kid) = k.kid() {
        claims.set_kid(kid);
    }
    let mut w = base64::write::EncoderStringWriter::new(url_safe_trailing_bits());
    serde_json::to_writer(&mut w, &claims.header)?;
    let mut buf = w.into_inner();
    buf.push('.');
    let mut w = base64::write::EncoderStringWriter::from(buf, url_safe_trailing_bits());
    serde_json::to_writer(&mut w, &claims.claims)?;
    let mut buf = w.into_inner();
    let sig = k.sign(buf.as_bytes())?;
    buf.push('.');
    let mut w = base64::write::EncoderStringWriter::from(buf, url_safe_trailing_bits());
    w.write_all(&sig)?;
    Ok(w.into_inner())
}
pub fn sign < ExtraClaims : Serialize > ( claims : & mut HeaderAndClaims < ExtraClaims > , k : & dyn SigningKey , ) -> Result < String > { claims . header . alg = k . alg ( ) . into ( ) ; if let Some ( kid ) = k . kid ( ) { claims . set_kid ( kid ) ; } let mut w = base64 :: write :: EncoderStringWriter :: new ( url_safe_trailing_bits ( ) ) ; serde_json :: to_writer ( & mut w , & claims . header ) ? ; let mut buf = w . into_inner ( ) ; buf . push ( '.' ) ; let mut w = base64 :: write :: EncoderStringWriter :: from ( buf , url_safe_trailing_bits ( ) ) ; serde_json :: to_writer ( & mut w , & claims . claims ) ? ; let mut buf = w . into_inner ( ) ; let sig = k . sign ( buf . as_bytes ( ) ) ? ; buf . push ( '.' ) ; let mut w = base64 :: write :: EncoderStringWriter :: from ( buf , url_safe_trailing_bits ( ) ) ; w . write_all ( & sig ) ? ; Ok ( w . into_inner ( ) ) }
Encode and sign this header and claims with the signing key.
Encode and sign this header and claims with the signing key .
claims
&mut HeaderAndClaims<ExtraClaims>
k
&dyn SigningKey
claims
&mut HeaderAndClaims<ExtraClaims>
k
&dyn SigningKey