class CZTop::ZAP::Request

Represents a ZAP request.

Attributes

address[RW]

@return [String, to_s]

credentials[RW]

@return [Array<String, to_s>] the credentials, 0 or more

domain[RW]

@return [String, to_s] the authentication domain

identity[RW]

@return [String, to_s] the connection identity

mechanism[RW]

@see Mechanisms @return [String, to_s] the security mechanism to be used

request_id[RW]

@return [String, to_s]

version[RW]

@return [String] ZAP version

Public Class Methods

from_message(msg) click to toggle source

Crafts a new {Request} from a message.

@param msg [CZTop::message] the message @return [Request] the request @raise [VersionMismatch] if the message contains an unsupported version

# File lib/cztop/zap.rb, line 43
def self.from_message(msg)
    version,       # The version frame, which SHALL contain the three octets "1.0".
    request_id,    # The request id, which MAY contain an opaque binary blob.
    domain,        # The domain, which SHALL contain a string.
    address,       # The address, the origin network IP address.
    identity,      # The identity, the connection Identity, if any.
    mechanism,     # The mechanism, which SHALL contain a string.
    *credentials = # The credentials, which SHALL be zero or more opaque frames.
      msg.to_a

  raise VersionMismatch if version != VERSION

  new(domain, credentials, mechanism: mechanism).tap do |r|
    r.version = version
    r.request_id = request_id
    r.address = address
    r.identity = identity
  end
end
new(domain, credentials = [], mechanism: Mechanisms::CURVE) click to toggle source

Initializes a new ZAP request. The security mechanism is set to CURVE (can be changed later).

@param domain [String] the domain within to authenticate @param credentials [Array<String>] the credentials of the user,

depending on the security mechanism used
# File lib/cztop/zap.rb, line 91
def initialize(domain, credentials = [], mechanism: Mechanisms::CURVE)
  @domain = domain
  @credentials = credentials
  @mechanism = mechanism
  @version = VERSION
end

Public Instance Methods

to_msg() click to toggle source

Creates a sendable message from this {Request}. @return [CZTop::Message} this request packed into a message

# File lib/cztop/zap.rb, line 100
def to_msg
  fields = [ @version, @request_id, @domain, @address,
    @identity, @mechanism, @credentials].flatten.map(&:to_s)

  CZTop::Message.new(fields)
end