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



100
101
102
103
104
105
# File 'lib/cztop/zap.rb', line 100

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)


85
86
87
# File 'lib/cztop/zap.rb', line 85

def address
  @address
end

#credentialsArray<String, #to_s>

Returns the credentials, 0 or more.

Returns:

  • (Array<String, #to_s>)

    the credentials, 0 or more



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

def credentials
  @credentials
end

#domainString, #to_s

Returns the authentication domain.

Returns:

  • (String, #to_s)

    the authentication domain



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

def domain
  @domain
end

#identityString, #to_s

Returns the connection identity.

Returns:

  • (String, #to_s)

    the connection identity



88
89
90
# File 'lib/cztop/zap.rb', line 88

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:



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

def mechanism
  @mechanism
end

#request_idString, #to_s

Returns:

  • (String, #to_s)


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

def request_id
  @request_id
end

#versionString

Returns ZAP version.

Returns:

  • (String)

    ZAP version



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

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:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cztop/zap.rb', line 52

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:



110
111
112
113
114
115
# File 'lib/cztop/zap.rb', line 110

def to_msg
  fields = [@version, @request_id, @domain, @address,
            @identity, @mechanism, @credentials].flatten.map(&:to_s)

  CZTop::Message.new(fields)
end