mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-23 18:50:12 +01:00
Upgraded to open_id_authentication plugin at 00d8bc7f97 and unpacked ruby-openid gem version 2.1.2.
This commit is contained in:
parent
6149900e0c
commit
e92dae2ffc
227 changed files with 30857 additions and 669 deletions
112
vendor/gems/ruby-openid-2.1.2/lib/hmac/hmac.rb
vendored
Normal file
112
vendor/gems/ruby-openid-2.1.2/lib/hmac/hmac.rb
vendored
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
# Copyright (C) 2001 Daiki Ueno <ueno@unixuser.org>
|
||||
# This library is distributed under the terms of the Ruby license.
|
||||
|
||||
# This module provides common interface to HMAC engines.
|
||||
# HMAC standard is documented in RFC 2104:
|
||||
#
|
||||
# H. Krawczyk et al., "HMAC: Keyed-Hashing for Message Authentication",
|
||||
# RFC 2104, February 1997
|
||||
#
|
||||
# These APIs are inspired by JCE 1.2's javax.crypto.Mac interface.
|
||||
#
|
||||
# <URL:http://java.sun.com/security/JCE1.2/spec/apidoc/javax/crypto/Mac.html>
|
||||
|
||||
module HMAC
|
||||
class Base
|
||||
def initialize(algorithm, block_size, output_length, key)
|
||||
@algorithm = algorithm
|
||||
@block_size = block_size
|
||||
@output_length = output_length
|
||||
@status = STATUS_UNDEFINED
|
||||
@key_xor_ipad = ''
|
||||
@key_xor_opad = ''
|
||||
set_key(key) unless key.nil?
|
||||
end
|
||||
|
||||
private
|
||||
def check_status
|
||||
unless @status == STATUS_INITIALIZED
|
||||
raise RuntimeError,
|
||||
"The underlying hash algorithm has not yet been initialized."
|
||||
end
|
||||
end
|
||||
|
||||
public
|
||||
def set_key(key)
|
||||
# If key is longer than the block size, apply hash function
|
||||
# to key and use the result as a real key.
|
||||
key = @algorithm.digest(key) if key.size > @block_size
|
||||
key_xor_ipad = "\x36" * @block_size
|
||||
key_xor_opad = "\x5C" * @block_size
|
||||
for i in 0 .. key.size - 1
|
||||
key_xor_ipad[i] ^= key[i]
|
||||
key_xor_opad[i] ^= key[i]
|
||||
end
|
||||
@key_xor_ipad = key_xor_ipad
|
||||
@key_xor_opad = key_xor_opad
|
||||
@md = @algorithm.new
|
||||
@status = STATUS_INITIALIZED
|
||||
end
|
||||
|
||||
def reset_key
|
||||
@key_xor_ipad.gsub!(/./, '?')
|
||||
@key_xor_opad.gsub!(/./, '?')
|
||||
@key_xor_ipad[0..-1] = ''
|
||||
@key_xor_opad[0..-1] = ''
|
||||
@status = STATUS_UNDEFINED
|
||||
end
|
||||
|
||||
def update(text)
|
||||
check_status
|
||||
# perform inner H
|
||||
md = @algorithm.new
|
||||
md.update(@key_xor_ipad)
|
||||
md.update(text)
|
||||
str = md.digest
|
||||
# perform outer H
|
||||
md = @algorithm.new
|
||||
md.update(@key_xor_opad)
|
||||
md.update(str)
|
||||
@md = md
|
||||
end
|
||||
alias << update
|
||||
|
||||
def digest
|
||||
check_status
|
||||
@md.digest
|
||||
end
|
||||
|
||||
def hexdigest
|
||||
check_status
|
||||
@md.hexdigest
|
||||
end
|
||||
alias to_s hexdigest
|
||||
|
||||
# These two class methods below are safer than using above
|
||||
# instance methods combinatorially because an instance will have
|
||||
# held a key even if it's no longer in use.
|
||||
def Base.digest(key, text)
|
||||
begin
|
||||
hmac = self.new(key)
|
||||
hmac.update(text)
|
||||
hmac.digest
|
||||
ensure
|
||||
hmac.reset_key
|
||||
end
|
||||
end
|
||||
|
||||
def Base.hexdigest(key, text)
|
||||
begin
|
||||
hmac = self.new(key)
|
||||
hmac.update(text)
|
||||
hmac.hexdigest
|
||||
ensure
|
||||
hmac.reset_key
|
||||
end
|
||||
end
|
||||
|
||||
private_class_method :new, :digest, :hexdigest
|
||||
end
|
||||
|
||||
STATUS_UNDEFINED, STATUS_INITIALIZED = 0, 1
|
||||
end
|
||||
11
vendor/gems/ruby-openid-2.1.2/lib/hmac/sha1.rb
vendored
Normal file
11
vendor/gems/ruby-openid-2.1.2/lib/hmac/sha1.rb
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
require 'hmac/hmac'
|
||||
require 'digest/sha1'
|
||||
|
||||
module HMAC
|
||||
class SHA1 < Base
|
||||
def initialize(key = nil)
|
||||
super(Digest::SHA1, 64, 20, key)
|
||||
end
|
||||
public_class_method :new, :digest, :hexdigest
|
||||
end
|
||||
end
|
||||
25
vendor/gems/ruby-openid-2.1.2/lib/hmac/sha2.rb
vendored
Normal file
25
vendor/gems/ruby-openid-2.1.2/lib/hmac/sha2.rb
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
require 'hmac/hmac'
|
||||
require 'digest/sha2'
|
||||
|
||||
module HMAC
|
||||
class SHA256 < Base
|
||||
def initialize(key = nil)
|
||||
super(Digest::SHA256, 64, 32, key)
|
||||
end
|
||||
public_class_method :new, :digest, :hexdigest
|
||||
end
|
||||
|
||||
class SHA384 < Base
|
||||
def initialize(key = nil)
|
||||
super(Digest::SHA384, 128, 48, key)
|
||||
end
|
||||
public_class_method :new, :digest, :hexdigest
|
||||
end
|
||||
|
||||
class SHA512 < Base
|
||||
def initialize(key = nil)
|
||||
super(Digest::SHA512, 128, 64, key)
|
||||
end
|
||||
public_class_method :new, :digest, :hexdigest
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue