Class: A2A::Types::AgentCardSignature
- Defined in:
- lib/a2a/types/agent_card.rb
Overview
Represents an agent card signature
Signatures provide cryptographic verification of agent cards using JSON Web Signature (JWS) format.
Instance Attribute Summary collapse
-
#protected_header ⇒ Object
readonly
Returns the value of attribute protected_header.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
Instance Method Summary collapse
-
#algorithm ⇒ String?
Get the algorithm from the protected header.
-
#decoded_header ⇒ Hash
Decode the protected header.
-
#initialize(signature:, protected_header:) ⇒ AgentCardSignature
constructor
Initialize a new agent card signature.
-
#uses_algorithm?(alg) ⇒ Boolean
Check if the signature uses a specific algorithm.
- #validate! ⇒ Object private
-
#validate_base64url_format(field) ⇒ Object
private
Validate base64url format.
-
#validate_protected_header_content ⇒ Object
private
Validate protected header content.
Methods inherited from BaseModel
#==, #camelize, from_h, from_json, #hash, #to_h, #to_json, underscore, #valid?, #validate_array_type, #validate_inclusion, #validate_required, #validate_type
Constructor Details
#initialize(signature:, protected_header:) ⇒ AgentCardSignature
Initialize a new agent card signature
457 458 459 460 461 |
# File 'lib/a2a/types/agent_card.rb', line 457 def initialize(signature:, protected_header:) @signature = signature @protected_header = protected_header validate! end |
Instance Attribute Details
#protected_header ⇒ Object (readonly)
Returns the value of attribute protected_header.
450 451 452 |
# File 'lib/a2a/types/agent_card.rb', line 450 def protected_header @protected_header end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
450 451 452 |
# File 'lib/a2a/types/agent_card.rb', line 450 def signature @signature end |
Instance Method Details
#algorithm ⇒ String?
Get the algorithm from the protected header
490 491 492 493 494 |
# File 'lib/a2a/types/agent_card.rb', line 490 def algorithm decoded_header["alg"] rescue StandardError nil end |
#decoded_header ⇒ Hash
Decode the protected header
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'lib/a2a/types/agent_card.rb', line 467 def decoded_header require "base64" require "json" # Add padding if needed for base64url decoding padded = @protected_header case padded.length % 4 when 2 padded += "==" when 3 padded += "=" end decoded = Base64.urlsafe_decode64(padded) JSON.parse(decoded) rescue StandardError => e raise ArgumentError, "Invalid protected header: #{e.}" end |
#uses_algorithm?(alg) ⇒ Boolean
Check if the signature uses a specific algorithm
501 502 503 |
# File 'lib/a2a/types/agent_card.rb', line 501 def uses_algorithm?(alg) algorithm == alg end |
#validate! ⇒ Object (private)
507 508 509 510 511 512 513 514 |
# File 'lib/a2a/types/agent_card.rb', line 507 def validate! validate_required(:signature, :protected_header) validate_type(:signature, String) validate_type(:protected_header, String) validate_base64url_format(:signature) validate_base64url_format(:protected_header) validate_protected_header_content end |
#validate_base64url_format(field) ⇒ Object (private)
Validate base64url format
520 521 522 523 524 525 |
# File 'lib/a2a/types/agent_card.rb', line 520 def validate_base64url_format(field) value = instance_variable_get("@#{field}") return if value.match?(/\A[A-Za-z0-9_-]+\z/) raise ArgumentError, "#{field} must be valid base64url encoded" end |
#validate_protected_header_content ⇒ Object (private)
Validate protected header content
529 530 531 532 533 534 535 536 537 |
# File 'lib/a2a/types/agent_card.rb', line 529 def validate_protected_header_content header = decoded_header unless header.is_a?(Hash) && header["alg"] raise ArgumentError, "protected_header must contain a valid algorithm" end rescue StandardError => e raise ArgumentError, "protected_header must be valid base64url encoded JSON: #{e.}" end |