Class: Botan::X509::Certificate
- Inherits:
-
Object
- Object
- Botan::X509::Certificate
- Defined in:
- lib/botan/x509/certificate.rb
Class Method Summary collapse
Instance Method Summary collapse
- #allowed_usage?(usage) ⇒ Boolean
- #authority_key_id ⇒ Object
- #fingerprint(hash_algo = 'SHA-256') ⇒ Object
-
#initialize(ptr) ⇒ Certificate
constructor
A new instance of Certificate.
- #inspect ⇒ Object
- #issuer_info(key, index = 0) ⇒ Object
- #serial_number ⇒ Object
- #subject_info(key, index = 0) ⇒ Object
- #subject_key_id ⇒ Object
- #subject_public_key ⇒ Object
- #subject_public_key_bits ⇒ Object
- #time_expires ⇒ Object
- #time_starts ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(ptr) ⇒ Certificate
Returns a new instance of Certificate.
16 17 18 19 20 21 |
# File 'lib/botan/x509/certificate.rb', line 16 def initialize(ptr) if ptr.null? raise Botan::Error, 'X509::Certificate received a NULL pointer' end @ptr = FFI::AutoPointer.new(ptr, self.class.method(:destroy)) end |
Class Method Details
.destroy(ptr) ⇒ Object
23 24 25 |
# File 'lib/botan/x509/certificate.rb', line 23 def self.destroy(ptr) LibBotan.botan_x509_cert_destroy(ptr) end |
.from_data(data) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/botan/x509/certificate.rb', line 33 def self.from_data(data) ptr = FFI::MemoryPointer.new(:pointer) buf = FFI::MemoryPointer.from_data(data) Botan.call_ffi(:botan_x509_cert_load, ptr, buf, buf.size) Certificate.new(ptr.read_pointer) end |
.from_file(filename) ⇒ Object
27 28 29 30 31 |
# File 'lib/botan/x509/certificate.rb', line 27 def self.from_file(filename) ptr = FFI::MemoryPointer.new(:pointer) Botan.call_ffi(:botan_x509_cert_load_file, ptr, filename) Certificate.new(ptr.read_pointer) end |
Instance Method Details
#allowed_usage?(usage) ⇒ Boolean
127 128 129 130 131 |
# File 'lib/botan/x509/certificate.rb', line 127 def allowed_usage?(usage) rc = Botan.call_ffi_rc(:botan_x509_cert_allowed_usage, @ptr, usage) rc.zero? end |
#authority_key_id ⇒ Object
87 88 89 90 91 |
# File 'lib/botan/x509/certificate.rb', line 87 def Botan.call_ffi_with_buffer(lambda { |b, bl| LibBotan.(@ptr, b, bl) }) end |
#fingerprint(hash_algo = 'SHA-256') ⇒ Object
74 75 76 77 78 79 |
# File 'lib/botan/x509/certificate.rb', line 74 def fingerprint(hash_algo = 'SHA-256') n = Botan::Digest.new(hash_algo).length * 3 Botan.call_ffi_with_buffer(lambda { |b, bl| LibBotan.botan_x509_cert_get_fingerprint(@ptr, hash_algo, b, bl) }, guess: n, string: true) end |
#inspect ⇒ Object
133 134 135 |
# File 'lib/botan/x509/certificate.rb', line 133 def inspect Botan.inspect_ptr(self) end |
#issuer_info(key, index = 0) ⇒ Object
115 116 117 118 119 |
# File 'lib/botan/x509/certificate.rb', line 115 def issuer_info(key, index = 0) Botan.call_ffi_with_buffer(lambda { |b, bl| LibBotan.botan_x509_cert_get_issuer_dn(@ptr, key, index, b, bl) }, string: true) end |
#serial_number ⇒ Object
81 82 83 84 85 |
# File 'lib/botan/x509/certificate.rb', line 81 def serial_number Botan.call_ffi_with_buffer(lambda { |b, bl| LibBotan.botan_x509_cert_get_serial_number(@ptr, b, bl) }) end |
#subject_info(key, index = 0) ⇒ Object
121 122 123 124 125 |
# File 'lib/botan/x509/certificate.rb', line 121 def subject_info(key, index = 0) Botan.call_ffi_with_buffer(lambda { |b, bl| LibBotan.botan_x509_cert_get_subject_dn(@ptr, key, index, b, bl) }, string: true) end |
#subject_key_id ⇒ Object
93 94 95 96 97 |
# File 'lib/botan/x509/certificate.rb', line 93 def subject_key_id Botan.call_ffi_with_buffer(lambda { |b, bl| LibBotan.botan_x509_cert_get_subject_key_id(@ptr, b, bl) }) end |
#subject_public_key ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/botan/x509/certificate.rb', line 105 def subject_public_key ptr = FFI::MemoryPointer.new(:pointer) Botan.call_ffi(:botan_x509_cert_get_public_key, @ptr, ptr) pub = ptr.read_pointer if pub.null? raise Botan::Error, 'botan_x509_cert_get_public_key returned NULL' end Botan::PK::PublicKey.new(pub) end |
#subject_public_key_bits ⇒ Object
99 100 101 102 103 |
# File 'lib/botan/x509/certificate.rb', line 99 def subject_public_key_bits Botan.call_ffi_with_buffer(lambda { |b, bl| LibBotan.botan_x509_cert_get_public_key_bits(@ptr, b, bl) }) end |
#time_expires ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/botan/x509/certificate.rb', line 54 def time_expires time = Botan.call_ffi_with_buffer(lambda { |b, bl| LibBotan.botan_x509_cert_get_time_expires(@ptr, b, bl) }, guess: 16, string: true) case time.size when 13 ::DateTime.strptime(time, '%y%m%d%H%M%SZ') when 15 ::DateTime.strptime(time, '%Y%m%d%H%M%SZ') else raise Botan::Error, 'X509::Certificate time_expires invalid format' end end |
#time_starts ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/botan/x509/certificate.rb', line 40 def time_starts time = Botan.call_ffi_with_buffer(lambda { |b, bl| LibBotan.botan_x509_cert_get_time_starts(@ptr, b, bl) }, guess: 16, string: true) case time.size when 13 ::DateTime.strptime(time, '%y%m%d%H%M%SZ') when 15 ::DateTime.strptime(time, '%Y%m%d%H%M%SZ') else raise Botan::Error, 'X509::Certificate time_starts invalid format' end end |
#to_s ⇒ Object
68 69 70 71 72 |
# File 'lib/botan/x509/certificate.rb', line 68 def to_s Botan.call_ffi_with_buffer(lambda { |b, bl| LibBotan.botan_x509_cert_to_string(@ptr, b, bl) }, string: true) end |