# Signature computation methods for OAuth 1.0
#
# This module provides a registry of signature methods that can be extended
# with custom implementations.
module SimpleOAuth
  module Signature
    # Type for signature implementation block
    type signature_block = ^(String secret, String signature_base) -> String

    # Type for registry entry
    type registry_entry = { implementation: signature_block, rsa: bool }

    # Registry of signature method implementations (class-level instance variable)
    self.@registry: Hash[String, registry_entry]

    # Registers a custom signature method
    def self.register: (String | Symbol name, ?rsa: bool) { (String, String) -> String } -> void

    # Checks if a signature method is registered
    def self.registered?: (String | Symbol name) -> bool

    # Returns list of registered signature method names
    def self.methods: () -> Array[String]

    # Checks if a signature method uses RSA
    def self.rsa?: (String | Symbol name) -> bool

    # Computes a signature using the specified method
    def self.sign: (String | Symbol name, String? secret, String signature_base) -> String

    # Unregisters a signature method
    def self.unregister: (String | Symbol name) -> void

    # Resets the registry to only built-in methods
    def self.reset!: () -> void

    # Encodes binary data as Base64 without newlines
    def self.encode_base64: (String data) -> String

    private

    # Normalizes signature method name for registry lookup
    def self.normalize_name: (String | Symbol name) -> String

    # Registers the built-in OAuth signature methods
    def self.register_builtin_methods: () -> void

    # Registers HMAC-based signature methods
    def self.register_hmac_methods: () -> void

    # Registers RSA-based signature methods
    def self.register_rsa_methods: () -> void

    # Registers the PLAINTEXT signature method
    def self.register_plaintext_method: () -> void
  end
end
