Crates.io | rails-cookie-parser |
lib.rs | rails-cookie-parser |
version | 0.1.0 |
source | src |
created_at | 2024-09-26 21:02:29.516482 |
updated_at | 2024-09-26 21:02:29.516482 |
description | A decryption library for Rails cookies |
homepage | |
repository | https://github.com/joshleaves/rails-cookie-parser |
max_upload_size | |
id | 1388033 |
size | 15,711 |
I already wrote something similar in Node.JS, and looking at Loco, I felt like it would be good to write some APIs in Rust and have them read sessions set in Rails.
Simple plug-n-use, don't forget to set your SECRET_KEY_BASE
:
use rails_cookie_parser::RailsCookieParser;
let parser = RailsCookieParser::default();
let Ok(result) = parser.decipher_cookie("my_cookie--is--very--long") else {
panic!("An error somewhere on the way");
}
Since Rails 7, the default hash digest is Sha256. If you want to use your Rails5 or Rails 6 sessions:
use rails_cookie_parser::RailsCookieParser;
let parser = RailsCookieParser::default_rails6();
let Ok(result) = parser.decipher_cookie("my_cookie--is--very--long") else {
panic!("An error somewhere on the way");
}
For a more complex usage, you can fine-tune things:
use rails_cookie_parser::{RailsCookieParser, HashDigest};
let rails_key = RailsCookieParser::new(
"secret_key_base" // Secret key base
"authenticated encrypted cookie", // Key salt
1000, // Iterations
HashDigest::Sha256 // HashDigest: Sha1 or Sha256
);
let Ok(result) = parser.decipher_cookie("my_cookie--is--very--long") else {
panic!("An error somewhere on the way");
}
Licensed under MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT).