Module: SimpleOAuth::Signature
- Defined in:
- lib/simple_oauth/signature.rb
Overview
Signature computation methods for OAuth 1.0
This module provides a registry of signature methods that can be extended with custom implementations. Built-in methods include HMAC-SHA1, HMAC-SHA256, RSA-SHA1, RSA-SHA256, and PLAINTEXT.
Class Method Summary collapse
-
.encode_base64(data) ⇒ String
Encodes binary data as Base64 without newlines.
-
.methods ⇒ Array<String>
Returns list of registered signature method names.
-
.register(name, rsa: false) {|secret, signature_base| ... } ⇒ void
Registers a custom signature method.
-
.registered?(name) ⇒ Boolean
Checks if a signature method is registered.
-
.reset! ⇒ void
Resets the registry to only built-in methods (useful for testing).
-
.rsa?(name) ⇒ Boolean
Checks if a signature method uses RSA (raw key instead of escaped secret).
-
.sign(name, secret, signature_base) ⇒ String
Computes a signature using the specified method.
-
.unregister(name) ⇒ void
Unregisters a signature method (useful for testing).
Class Method Details
.encode_base64(data) ⇒ String
Encodes binary data as Base64 without newlines
129 130 131 |
# File 'lib/simple_oauth/signature.rb', line 129 def encode_base64(data) Base64.strict_encode64(data) end |
.methods ⇒ Array<String>
Returns list of registered signature method names
64 65 66 |
# File 'lib/simple_oauth/signature.rb', line 64 def methods @registry.keys end |
.register(name, rsa: false) {|secret, signature_base| ... } ⇒ void
This method returns an undefined value.
Registers a custom signature method
43 44 45 |
# File 'lib/simple_oauth/signature.rb', line 43 def register(name, rsa: false, &block) @registry[normalize_name(name)] = {implementation: block, rsa: rsa} end |
.registered?(name) ⇒ Boolean
Checks if a signature method is registered
54 55 56 |
# File 'lib/simple_oauth/signature.rb', line 54 def registered?(name) @registry.key?(normalize_name(name)) end |
.reset! ⇒ void
This method returns an undefined value.
Resets the registry to only built-in methods (useful for testing)
116 117 118 119 |
# File 'lib/simple_oauth/signature.rb', line 116 def reset! @registry.clear register_builtin_methods end |
.rsa?(name) ⇒ Boolean
Checks if a signature method uses RSA (raw key instead of escaped secret)
76 77 78 |
# File 'lib/simple_oauth/signature.rb', line 76 def rsa?(name) @registry.dig(normalize_name(name), :rsa) || false end |
.sign(name, secret, signature_base) ⇒ String
Computes a signature using the specified method
90 91 92 93 94 95 96 97 |
# File 'lib/simple_oauth/signature.rb', line 90 def sign(name, secret, signature_base) normalized = normalize_name(name) entry = @registry.fetch(normalized) do raise ArgumentError, "Unknown signature method: #{name}. " \ "Registered methods: #{@registry.keys.join(", ")}" end entry.fetch(:implementation).call(secret, signature_base) end |
.unregister(name) ⇒ void
This method returns an undefined value.
Unregisters a signature method (useful for testing)
106 107 108 |
# File 'lib/simple_oauth/signature.rb', line 106 def unregister(name) @registry.delete(normalize_name(name)) end |