Class: Ronin::Web::SessionCookie::Cookie

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ronin/web/session_cookie/cookie.rb

Overview

Base class for all session cookie classes.

Direct Known Subclasses

Django, JWT, Rack

Constant Summary collapse

STRICT_BASE64_REGEXP =

Regular expression for a URI decoded Base64 blob.

%r{(?:[A-Za-z0-9+/]{4})+(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?|[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=}
URI_ENCODED_BASE64_REGEXP =

Regular expression for a URI escaped Base64 blob.

%r{(?:[A-Za-z0-9+/]{4})+(?:[A-Za-z0-9+/]{2}%3D%3D|[A-Za-z0-9+/]{3}%3D)?|[A-Za-z0-9+/]{2}%3D|[A-Za-z0-9+/]{3}%3D}
URL_SAFE_BASE64_REGEXP =

Regular expression for a URL-safe encoded Base64 blob.

/[A-Za-z0-9_-]{2,}/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Cookie

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the session cookie.

Parameters:

  • params (Hash)

    The parsed contents of the session cookie.



51
52
53
# File 'lib/ronin/web/session_cookie/cookie.rb', line 51

def initialize(params)
  @params = params
end

Instance Attribute Details

#paramsHash (readonly)

The cookie params.

Returns:

  • (Hash)


41
42
43
# File 'lib/ronin/web/session_cookie/cookie.rb', line 41

def params
  @params
end

Class Method Details

.extract(response) ⇒ Cookie?

This method is abstract.

Extracts and parses the session cookie from an HTTP response.

Parameters:

  • response (Net::HTTPResponse)

    The HTTP response object.

Returns:

  • (Cookie, nil)

    The parsed session cookie or nil if no session cookie could be detected.

Raises:

  • (NotImplementedError)


99
100
101
# File 'lib/ronin/web/session_cookie/cookie.rb', line 99

def self.extract(response)
  raise(NotImplementedError,"#{self}.extract was not implemented")
end

.identify?(string) ⇒ Boolean

This method is abstract.

Determines if the given string is a valid session cookie.

Parameters:

  • string (String)

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


66
67
68
# File 'lib/ronin/web/session_cookie/cookie.rb', line 66

def self.identify?(string)
  raise(NotImplementedError,"#{self}.identify? was not implemented")
end

.parse(string) ⇒ Cookie

This method is abstract.

Parses a session cookie value.

Parameters:

  • string (String)

Returns:

Raises:

  • (NotImplementedError)


81
82
83
# File 'lib/ronin/web/session_cookie/cookie.rb', line 81

def self.parse(string)
  raise(NotImplementedError,"#{self}.parse was not implemented")
end

Instance Method Details

#[](key) ⇒ Object?

Returns the value for the given session cookie param.

Parameters:

  • key (String)

Returns:

  • (Object, nil)


125
126
127
# File 'lib/ronin/web/session_cookie/cookie.rb', line 125

def [](key)
  @params[key]
end

#each {|key, value| ... } ⇒ Enumerator

Enumerates over the params within the session cookie.

Yields:

  • (key, value)

Yield Parameters:

  • key (String)
  • value (Object)

Returns:

  • (Enumerator)


142
143
144
# File 'lib/ronin/web/session_cookie/cookie.rb', line 142

def each(&block)
  @params.each(&block)
end

#has_key?(params) ⇒ Boolean

Determines if the session cookie contains the given param.

Parameters:

  • params (String)

Returns:

  • (Boolean)


112
113
114
# File 'lib/ronin/web/session_cookie/cookie.rb', line 112

def has_key?(params)
  @params.has_key?(params)
end

#to_hHash

Converts the session cookie into a Hash.

Returns:

  • (Hash)


153
154
155
# File 'lib/ronin/web/session_cookie/cookie.rb', line 153

def to_h
  @params
end