Module: String::OpenID

### Home Classes Methods

### In Files

- lib/openid/util.rb

### Methods

- #append_args
- #from_btwoc
- #parse_kv
- #parse_link_attrs
- #sign_reply
- #url_encode

### Class/Module Index

Quicksearch

- OpenID
- OpenID::Association
- OpenID::AssociationManager
- OpenID::AuthenticationError
- OpenID::BaseAssociationManager
- OpenID::Consumer
- OpenID::ConsumerAssociation
- OpenID::DiffieHelmanAssociator
- OpenID::DumbAssociationManager
- OpenID::NoArgumentsError
- OpenID::NoOpenIDArgs
- OpenID::ProtocolError
- OpenID::Request
- OpenID::Response
- OpenID::ServerAssociation
- OpenID::SimpleHTTPClient
- OpenID::UserCancelled
- OpenID::UserSetupNeeded
- OpenID::ValueMismatchError
- String
- String::OpenID
- Bignum
- Crypto_math
- DateTime
- Fixnum

No matching classes.

# String::OpenID

### Public Instance Methods

append_args(url, args) click to toggle source

Appends arguments in hash args to the existing url string

    # File lib/openid/util.rb, line 90
    def append_args(url, args)
            return url if args.empty?
            return url + (url.include? '?' and '&' or '?') + url_encode(args)
    end

from_btwoc(str) click to toggle source

Converts a raw string containing a big endian two's complement number into a Fixnum or Bignum

    # File lib/openid/util.rb, line 95
    def from_btwoc(str)
            # Maybe this should be part of a btwoc class or something

            str = "\0000" * (4 - (str.length % 4)) + str
            num = 0
            str.unpack('N*').each { |x|
                    num <<= 32
                    num |= x
            }
            return num
    end

parse_kv(d) click to toggle source

Parses an OpenID Key Value string(A new-line separated list containing key:value pairs). Returns a hash.

    # File lib/openid/util.rb, line 107
    def parse_kv(d)
            d.strip!
            args = {}
            d.split("\n").each { |line|
                    pair = line.split(':',2)
                    if pair.length == 2
                            k, v = pair
                            args[k.strip] = v.strip
                    end
            }
            return args
    end

parse_link_attrs(data) click to toggle source

Takes a string containing html, and yields the attributes of each link tags until a body tag is found.

    # File lib/openid/util.rb, line 120
    def parse_link_attrs(data)
            parser = HTMLTokenizer.new(data)
            while el = parser.getTag('link', 'body')
                    if el.tag_name == 'link'
                            yield el.attr_hash
                    elsif el.tag_name == 'body'
                            return
                    end
            end

    end

sign_reply(reply, key, signed_fields) click to toggle source

Generates a signature for a set of fields. reply is a hash containing the data that was signed, key is the secret key, and signed_fields is an array containing the names (in order) of the fields to be signed.

    Returns the list of signed fields (comma separated) and the base64 encoded signature

    # File lib/openid/util.rb, line 136
    def sign_reply(reply, key, signed_fields)
            token = ''
            signed_fields.each { |x|
                    token += x + ':' + reply['openid.' + x] + "\n"
            }
            d = Base64.encode64(HMAC::SHA1.digest(key,token)).delete("\n")
            return signed_fields.join(','), d
    end

url_encode(query) click to toggle source

Takes all entries in a hash and combines and escapes them (using CGI::escape) into a single string.

    # File lib/openid/util.rb, line 81
    def url_encode(query)
            output = ''
            query.each { |key, val|
                    output += CGI::escape(key.to_s) + '=' + CGI::escape(val.to_s) + '&'
            }
            output.chop!
            return output
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.