Class: Longfellow::Attribute
- Inherits:
-
Object
- Object
- Longfellow::Attribute
- Defined in:
- lib/longfellow/attribute.rb
Overview
A claim that the prover must open and the verifier checks: a single mdoc attribute identified by its namespace and element identifier, together with the expected value encoded as the raw bytes of its CBOR representation.
Mirrors the C ‘RequestedAttribute` struct. The fixed-size C buffers bound the lengths: namespace_id <= 64, id <= 32, cbor_value <= 64 bytes.
Constant Summary collapse
- MAX_NAMESPACE =
64- MAX_ID =
32- MAX_CBOR_VALUE =
64
Instance Attribute Summary collapse
-
#cbor_value ⇒ Object
readonly
Returns the value of attribute cbor_value.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#namespace_id ⇒ Object
readonly
Returns the value of attribute namespace_id.
Class Method Summary collapse
-
.coerce(obj) ⇒ Object
Coerce a Hash or Attribute into an Attribute.
Instance Method Summary collapse
-
#initialize(namespace_id:, id:, cbor_value:) ⇒ Attribute
constructor
A new instance of Attribute.
-
#write_to(struct) ⇒ Object
Populate a C::RequestedAttribute struct (backed by zeroed memory).
Constructor Details
#initialize(namespace_id:, id:, cbor_value:) ⇒ Attribute
Returns a new instance of Attribute.
20 21 22 23 24 25 |
# File 'lib/longfellow/attribute.rb', line 20 def initialize(namespace_id:, id:, cbor_value:) @namespace_id = String(namespace_id).b @id = String(id).b @cbor_value = String(cbor_value).b validate! end |
Instance Attribute Details
#cbor_value ⇒ Object (readonly)
Returns the value of attribute cbor_value.
15 16 17 |
# File 'lib/longfellow/attribute.rb', line 15 def cbor_value @cbor_value end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/longfellow/attribute.rb', line 15 def id @id end |
#namespace_id ⇒ Object (readonly)
Returns the value of attribute namespace_id.
15 16 17 |
# File 'lib/longfellow/attribute.rb', line 15 def namespace_id @namespace_id end |
Class Method Details
.coerce(obj) ⇒ Object
Coerce a Hash or Attribute into an Attribute.
28 29 30 31 32 33 34 35 36 |
# File 'lib/longfellow/attribute.rb', line 28 def self.coerce(obj) case obj when Attribute then obj when Hash then new(**obj.transform_keys(&:to_sym)) else raise ArgumentError, "expected Longfellow::Attribute or Hash, got #{obj.class}" end end |
Instance Method Details
#write_to(struct) ⇒ Object
Populate a C::RequestedAttribute struct (backed by zeroed memory).
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/longfellow/attribute.rb', line 39 def write_to(struct) ptr = struct.to_ptr ptr.put_bytes(struct.offset_of(:namespace_id), @namespace_id) unless @namespace_id.empty? ptr.put_bytes(struct.offset_of(:id), @id) unless @id.empty? ptr.put_bytes(struct.offset_of(:cbor_value), @cbor_value) unless @cbor_value.empty? struct[:namespace_len] = @namespace_id.bytesize struct[:id_len] = @id.bytesize struct[:cbor_value_len] = @cbor_value.bytesize struct end |