Struct RailsCookieParser

Source
pub struct RailsCookieParser { /* private fields */ }
Expand description

Base object and structure

Implementations§

Source§

impl RailsCookieParser

Source

pub fn default_rails5() -> Self

Default builder for a Rails 5 cookie

Calls the same implementation as Self::default_rails6().

Source

pub fn default_rails6() -> Self

Default builder for a Rails 6 cookie

Functions just like Self::default(), but uses the pre-Rails 7 hash of Sha1.

Source

pub fn default_rails7() -> Self

Default builder for a Rails 7 cookie

Since Rails 7 is the latest stable, the implementation is exactly the same as Self::default().

Source

pub fn new( key_base: &str, key_salt: &str, iterations: u32, key_hash: HashDigest, ) -> Self

Creates a new decryption object

All arguments can be customised in case you have a very specific setup for your Rails server.

Most of the time, you can use the default functions, but here, you can add all the customisation you require:

  • key_base: Your Rails SECRET_KEY_BASE string.
  • key_salt: Your Rails salt string. If unsure, just use "authenticated encrypted cookie".
  • iterations: Unless you know you changed it, 1000.
  • key_hash: Can be Sha1 or Sha256 depending on your Rails version.

Decipher a cookie into a JSON string

Only the decryption is done, this library will not tell you how to use the resulting JSON.

Trait Implementations§

Source§

impl Default for RailsCookieParser

Source§

fn default() -> Self

Default implementation for RailsCookieParser

The default implementation is meant to be “plug and play” and uses Rails 7 defaults, which are:

  • Key base is taken from ENV value for SECRET_KEY_BASE.
  • Key salt is Rails default "authenticated encrypted cookie".
  • Iterations: 1000.
  • Hash digest is Sha256 since Rails 7.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.