Class: Mechanize::Form::Keygen

### Home Classes Methods

### In Files

- lib/mechanize/form/keygen.rb

### Parent

Mechanize::Form::Field

### Methods

- ::new
- #generate_key

### Files

- EXAMPLES.rdoc
- GUIDE.rdoc
- LICENSE.rdoc
- Manifest.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Mechanize
- Mechanize::ChunkedTerminationError
- Mechanize::ContentTypeError
- Mechanize::Cookie
- Mechanize::CookieCMethods
- Mechanize::CookieDeprecated
- Mechanize::CookieIMethods
- Mechanize::CookieJar
- Mechanize::CookieJarIMethods
- Mechanize::DirectorySaver
- Mechanize::Download
- Mechanize::ElementMatcher
- Mechanize::ElementNotFoundError
- Mechanize::Error
- Mechanize::File
- Mechanize::FileConnection
- Mechanize::FileRequest
- Mechanize::FileResponse
- Mechanize::FileSaver
- Mechanize::Form
- Mechanize::Form::Button
- Mechanize::Form::CheckBox
- Mechanize::Form::Field
- Mechanize::Form::FileUpload
- Mechanize::Form::Hidden
- Mechanize::Form::ImageButton
- Mechanize::Form::Keygen
- Mechanize::Form::MultiSelectList
- Mechanize::Form::Option
- Mechanize::Form::RadioButton
- Mechanize::Form::Reset
- Mechanize::Form::SelectList
- Mechanize::Form::Submit
- Mechanize::Form::Text
- Mechanize::Form::Textarea
- Mechanize::HTTP
- Mechanize::HTTP::Agent
- Mechanize::HTTP::AuthChallenge
- Mechanize::HTTP::AuthRealm
- Mechanize::HTTP::AuthStore
- Mechanize::HTTP::ContentDispositionParser
- Mechanize::HTTP::WWWAuthenticateParser
- Mechanize::Headers
- Mechanize::History
- Mechanize::Image
- Mechanize::Page
- Mechanize::Page::Base
- Mechanize::Page::Frame
- Mechanize::Page::Image
- Mechanize::Page::Label
- Mechanize::Page::Link
- Mechanize::Page::MetaRefresh
- Mechanize::Parser
- Mechanize::PluggableParser
- Mechanize::Prependable
- Mechanize::RedirectLimitReachedError
- Mechanize::RedirectNotGetOrHeadError
- Mechanize::ResponseCodeError
- Mechanize::ResponseReadError
- Mechanize::RobotsDisallowedError
- Mechanize::TestCase
- Mechanize::UnauthorizedError
- Mechanize::UnsupportedSchemeError
- Mechanize::Util
- Mechanize::XmlFile
- HTTP
- HTTP::CookieJar

No matching classes.

# Mechanize::Form::Keygen

This class represents a keygen (public / private key generator) found in a Form. The field will automatically generate a key pair and compute its own value to match the challenge. Call key to access the public/private key pair.

### Attributes

challenge[R]

The challenge for this <keygen>.

key[R]

The key associated with this <keygen> tag.

### Public Class Methods

new(node, value = nil) click to toggle source

    # File lib/mechanize/form/keygen.rb, line 14
    def initialize(node, value = nil)
      super
      @challenge = node['challenge']

      @spki = OpenSSL::Netscape::SPKI.new
      @spki.challenge = @challenge

      @key = nil
      generate_key if value.nil? || value.empty?
    end

### Public Instance Methods

generate_key(key_size = 2048) click to toggle source

Generates a key pair and sets the field's value.

    # File lib/mechanize/form/keygen.rb, line 26
    def generate_key(key_size = 2048)
      # Spec at http://dev.w3.org/html5/spec/Overview.html#the-keygen-element
      @key = OpenSSL::PKey::RSA.new key_size
      @spki.public_key = @key.public_key
      @spki.sign @key, OpenSSL::Digest::MD5.new
      self.value = @spki.to_pem
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.