GithubHelp home page GithubHelp logo

badboy / nobsign Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 0.0 1019 KB

A simple but effective sign library, written in Rust

Home Page: https://docs.rs/crate/nobsign

License: BSD 3-Clause "New" or "Revised" License

Rust 100.00%

nobsign's Introduction

nobsign

crates.io Build Status

A simple but effective sign library, written in Rust.

Ported from nobi, which itself is a port of itsdangerous.

Documentation

Online Documentation.

Possible use cases

  • Creating an activation link for users
  • Creating a password reset link

Basic Example:

use nobsign::Signer;
let signer = Signer::new(b"my secret");

// Let's say the user's ID is 101
let signed = signer.sign("101");

// You can now email this url to your users!
let url = format!("http://yoursite.com/activate/?key={}", signed);

// Later check the signature and get the value back
let unsigned = signer.unsign(&signed).unwrap();

Example with timestamped signatures

use nobsign::TimestampSigner;
let signer = TimestampSigner::new(b"my secret");

// Let's say the user's ID is 101
let signed = signer.sign("101");

// You can now email this url to your users!
let url = format!("http://yoursite.com/activate/?key={}", signed);

// In your code, you can verify the expiration:
signer.unsign(&signed, 86400).unwrap(); // 1 day expiration

nobsign's People

Contributors

badboy avatar briansmith avatar homu avatar serprex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nobsign's Issues

The type of `secret` parameters should be `&[u8]`, not `String`

Here is how one would go about creating a secure key for use with nobsign:

fn make_key() -> Result<Vec<u8>, ()> {
     use ring::{digest, rand};
     let key = vec![0u8; digest::SHA1.digest_len];
     try!(rand::fill_secure_random(&mut key[..]));
     Ok(key)
}

However, such a secure key won't work because nobsign uses String as the type of the secret, and Rust's String type only allows UTF-8 encoded values. Rust's insistence on String and &str being UTF-8 encoded means that they can never be used for storing a secure key.

Because of the weird way that HMAC handles large key sizes, BASE64-encoding the key to store it in a String would not be as secure as expected, either.

New release on crates.io?

The current version fails to compile due to an invalid ring dependency:

error: failed to select a version for the requirement `ring = "^0.2.3"`
  candidate versions found which didn't match: 0.14.1, 0.14.0, 0.13.5, ...
  location searched: crates.io index
required by package `nobsign v0.1.0`
    ... 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.