django-signing-rust
This crate implements Django's cryptographic signing of strings and objects for Rust.
use ;
use django_signing;
const SECRET: & = b"my-secret-key";
const SALT: & = b"demo-salt";
let book = Book ;
let signed = dumps;
println!;
// This prints something like:
// Signed value: eyJ0aXRsZSI6IlRoZSBMb3JkIG9mIHRoZSBSaW5ncyIsImF1dGhvciI6IkouIFIuIFIuIFRvbGtpZW4iLCJ5ZWFyIjoxOTU0fQ:1n5aMt:Q7rI7rBXrLmMFsxLPnkiLl1GCr_ygqsM0nHBkazgvYc
let unsigned: Book = loads.unwrap;
println!;
// This prints:
// Unsigned value: Book { title: "The Lord of the Rings", author: "J. R. R. Tolkien", year: 1954 }
There's also access to the BaseSigner and TimestampSigner structs which
relate to Django's
Signer
and
TimestampSigner
classes, respectively.
The library only supports SHA-256, since SHA-1 is typically a bad idea these days!