Class: Rnp::Verify::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/rnp/op/verify.rb

Overview

Class representing an individual signature.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ Signature

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Signature.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/rnp/op/verify.rb', line 85

def initialize(ptr)
  # status
  @status = LibRnp.rnp_op_verify_signature_get_status(ptr)
  pptr = FFI::MemoryPointer.new(:pointer)

  # creation and expiration
  pcreation_time = FFI::MemoryPointer.new(:uint32)
  pexpiration_time = FFI::MemoryPointer.new(:uint32)
  Rnp.call_ffi(:rnp_op_verify_signature_get_times, ptr, pcreation_time,
               pexpiration_time)
  @creation_time = Time.at(pcreation_time.read(:uint32))
  @expiration_time = pexpiration_time.read(:uint32)

  # hash
  Rnp.call_ffi(:rnp_op_verify_signature_get_hash, ptr, pptr)
  begin
    phash = pptr.read_pointer
    @hash = phash.read_string unless phash.null?
  ensure
    LibRnp.rnp_buffer_destroy(phash)
  end

  # key
  Rnp.call_ffi(:rnp_op_verify_signature_get_key, ptr, pptr)
  pkey = pptr.read_pointer
  @key = Key.new(pkey) unless pkey.null?
end

Instance Attribute Details

#creation_timeTime (readonly)

The creation time of the signature

Returns:

  • (Time)


79
80
81
# File 'lib/rnp/op/verify.rb', line 79

def creation_time
  @creation_time
end

#expiration_timeInteger (readonly)

The expiration (as the number of seconds after #creation_time)

Returns:

  • (Integer)


82
83
84
# File 'lib/rnp/op/verify.rb', line 82

def expiration_time
  @expiration_time
end

#hashString (readonly)

The hash algorithm used for the signature

Returns:

  • (String)


73
74
75
# File 'lib/rnp/op/verify.rb', line 73

def hash
  @hash
end

#keyKey (readonly)

The key that created the signature

Returns:



76
77
78
# File 'lib/rnp/op/verify.rb', line 76

def key
  @key
end

#statusObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



70
71
72
# File 'lib/rnp/op/verify.rb', line 70

def status
  @status
end

Instance Method Details

#expired?Boolean

Check if this signature is expired.

Returns:

  • (Boolean)

    true if the signature is expired



133
134
135
# File 'lib/rnp/op/verify.rb', line 133

def expired?
  @status == LibRnp::RNP_ERROR_SIGNATURE_EXPIRED
end

#good?Boolean

Check if this signature is good.

Returns:

  • (Boolean)

    true if the signature is valid and not expired



116
117
118
# File 'lib/rnp/op/verify.rb', line 116

def good?
  @status == LibRnp::RNP_SUCCESS
end

#valid?Boolean

Note:

A valid signature may also be expired.

Check if this signature is valid.

Returns:

  • (Boolean)

    true if the signature is valid



125
126
127
128
# File 'lib/rnp/op/verify.rb', line 125

def valid?
  @status == LibRnp::RNP_SUCCESS ||
    @status == LibRnp::RNP_ERROR_SIGNATURE_EXPIRED
end