Class: Hawk::Crypto::Bewit
Instance Attribute Summary collapse
-
#ext ⇒ Object
readonly
Returns the value of attribute ext.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#ts ⇒ Object
readonly
Returns the value of attribute ts.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #encode64 ⇒ Object
-
#initialize(id, key, options, algorithm = 'sha256') ⇒ Bewit
constructor
A new instance of Bewit.
- #mac ⇒ Object
- #normalized_string ⇒ Object
- #to_s(options = {}) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(id, key, options, algorithm = 'sha256') ⇒ Bewit
Returns a new instance of Bewit.
153 154 155 156 157 158 |
# File 'lib/hawk/crypto.rb', line 153 def initialize(id, key, , algorithm = 'sha256') @ts = [:ts] ||= Time.now.to_i + [:ttl].to_i @ext = [:ext] @id, @key, @options, @algorithm = id, key, .dup, algorithm @mac = .delete(:mac) if [:mac] end |
Instance Attribute Details
#ext ⇒ Object (readonly)
Returns the value of attribute ext.
152 153 154 |
# File 'lib/hawk/crypto.rb', line 152 def ext @ext end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
152 153 154 |
# File 'lib/hawk/crypto.rb', line 152 def id @id end |
#ts ⇒ Object (readonly)
Returns the value of attribute ts.
152 153 154 |
# File 'lib/hawk/crypto.rb', line 152 def ts @ts end |
Class Method Details
.decode(bewit) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/hawk/crypto.rb', line 145 def self.decode(bewit) padding = '=' * ((4 - bewit.size) % 4) id, , mac, ext = Base64.decode64(bewit + padding).split('\\') new(id, nil, { :mac => mac, :ext => ext, :ts => }, nil) end |
Instance Method Details
#==(other) ⇒ Object
185 186 187 188 189 190 191 192 |
# File 'lib/hawk/crypto.rb', line 185 def ==(other) if self.class === other mac == other.mac else # assume base64 encoded bewit self == self.class.decode(other) end end |
#encode64 ⇒ Object
177 178 179 |
# File 'lib/hawk/crypto.rb', line 177 def encode64 @encoded ||= Base64.urlsafe_encode64(normalized_string).chomp.sub(/=+\Z/, '') end |
#mac ⇒ Object
160 161 162 |
# File 'lib/hawk/crypto.rb', line 160 def mac @mac ||= Crypto::Mac.new(@key, @options.merge(:type => 'bewit'), @algorithm) end |
#normalized_string ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/hawk/crypto.rb', line 164 def normalized_string @normalized_string ||= begin parts = [] parts << @id parts << @ts parts << mac.to_s parts << @ext parts.join("\\") end end |
#to_s(options = {}) ⇒ Object
181 182 183 |
# File 'lib/hawk/crypto.rb', line 181 def to_s( = {}) encode64 end |