Struct detached_jws::encode::SerializeJwsWriter[][src]

pub struct SerializeJwsWriter<W, S: Write> { /* fields omitted */ }

A Write implementation serialize to detached jws

Examples

extern crate detached_jws;
extern crate anyhow;
extern crate serde_json;

use std::io::{Write};
use anyhow::Result;
use serde_json::{json, Map};
use detached_jws::{SerializeJwsWriter, Sign};

#[derive(Default)]
pub struct DummySigner(Vec<u8>);

impl Sign for DummySigner {
    fn get_sign(&self) -> Result<Vec<u8>> {
        Ok(self.0.clone())
    }
}

impl Write for DummySigner {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        self.0.write(buf)
    }
    fn flush(&mut self) -> std::io::Result<()> {
       Ok(())
    }
}

let mut header = Map::new();
header.insert("custom".to_owned(), json!("custom_value"));

let mut writer = SerializeJwsWriter::new(Vec::new(),
       "test_algorithm".to_owned(),
       header,
       DummySigner::default()).unwrap();
writer.write_all(&[0, 1, 2, 3]);
writer.write_all(&[4, 5, 6]);

let jws = writer.finish().unwrap();

assert_eq!(
       String::from_utf8(jws).unwrap(),
       "eyJhbGciOiJ0ZXN0X2FsZ29yaXRobSIsImN1c3RvbSI6ImN1c3RvbV92YWx1ZSJ9..ZXlKaGJHY2lPaUowWlhOMFgyRnNaMjl5YVhSb2JTSXNJbU4xYzNSdmJTSTZJbU4xYzNSdmJWOTJZV3gxWlNKOS5BQUVDQXdRRkJn");

Implementations

impl<W, S> SerializeJwsWriter<W, S> where
    W: Write,
    S: Sign
[src]

pub fn new(
    mut writer: W,
    algorithm: String,
    mut header: JwsHeader,
    mut signer: S
) -> Result<Self>
[src]

pub fn finish(&mut self) -> Result<W>[src]

Trait Implementations

impl<W, S> Write for SerializeJwsWriter<W, S> where
    S: Write
[src]

Auto Trait Implementations

impl<W, S> RefUnwindSafe for SerializeJwsWriter<W, S> where
    S: RefUnwindSafe,
    W: RefUnwindSafe
[src]

impl<W, S> Send for SerializeJwsWriter<W, S> where
    S: Send,
    W: Send
[src]

impl<W, S> Sync for SerializeJwsWriter<W, S> where
    S: Sync,
    W: Sync
[src]

impl<W, S> Unpin for SerializeJwsWriter<W, S> where
    S: Unpin,
    W: Unpin
[src]

impl<W, S> UnwindSafe for SerializeJwsWriter<W, S> where
    S: UnwindSafe,
    W: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.