Class: CZTop::ZAP::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/cztop/zap.rb

Overview

Represents a ZAP request.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, credentials = [], mechanism: Mechanisms::CURVE) ⇒ Request

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

Parameters:

  • domain (String)

    the domain within to authenticate

  • credentials (Array<String>) (defaults to: [])

    the credentials of the user, depending on the security mechanism used


91
92
93
94
95
96
# File 'lib/cztop/zap.rb', line 91

def initialize(domain, credentials = [], mechanism: Mechanisms::CURVE)
  @domain = domain
  @credentials = credentials
  @mechanism = mechanism
  @version = VERSION
end

Instance Attribute Details

#addressString, #to_s

Returns:

  • (String, #to_s)

76
77
78
# File 'lib/cztop/zap.rb', line 76

def address
  @address
end

#credentialsArray<String, #to_s>

Returns the credentials, 0 or more.

Returns:

  • (Array<String, #to_s>)

    the credentials, 0 or more


70
71
72
# File 'lib/cztop/zap.rb', line 70

def credentials
  @credentials
end

#domainString, #to_s

Returns the authentication domain.

Returns:

  • (String, #to_s)

    the authentication domain


67
68
69
# File 'lib/cztop/zap.rb', line 67

def domain
  @domain
end

#identityString, #to_s

Returns the connection identity.

Returns:

  • (String, #to_s)

    the connection identity


79
80
81
# File 'lib/cztop/zap.rb', line 79

def identity
  @identity
end

#mechanismString, #to_s

Returns the security mechanism to be used.

Returns:

  • (String, #to_s)

    the security mechanism to be used

See Also:


83
84
85
# File 'lib/cztop/zap.rb', line 83

def mechanism
  @mechanism
end

#request_idString, #to_s

Returns:

  • (String, #to_s)

73
74
75
# File 'lib/cztop/zap.rb', line 73

def request_id
  @request_id
end

#versionString

Returns ZAP version.

Returns:

  • (String)

    ZAP version


64
65
66
# File 'lib/cztop/zap.rb', line 64

def version
  @version
end

Class Method Details

.from_message(msg) ⇒ Request

Crafts a new CZTop::ZAP::Request from a message.

Parameters:

  • msg (CZTop::message)

    the message

Returns:

Raises:


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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

Instance Method Details

#to_msgCZTop::Message

Creates a sendable message from this CZTop::ZAP::Request.

Returns:


100
101
102
103
104
105
# 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