Module: Botan
- Defined in:
- lib/botan/error.rb,
lib/botan/kdf.rb,
lib/botan/mac.rb,
lib/botan/rng.rb,
lib/botan/utils.rb,
lib/botan/bcrypt.rb,
lib/botan/cipher.rb,
lib/botan/digest.rb,
lib/botan/version.rb,
lib/botan/defaults.rb,
lib/botan/pk/mceies.rb,
lib/botan/pk/op/sign.rb,
lib/botan/pk/op/verify.rb,
lib/botan/pk/publickey.rb,
lib/botan/pk/op/decrypt.rb,
lib/botan/pk/op/encrypt.rb,
lib/botan/pk/privatekey.rb,
lib/botan/x509/certificate.rb,
lib/botan/x509/constraints.rb,
lib/botan/pk/op/keyagreement.rb
Overview
© 2017 Ribose Inc.
Defined Under Namespace
Modules: BCrypt, KDF, PK, X509 Classes: Cipher, Digest, Error, MAC, RNG
Constant Summary collapse
- VERSION =
'0.1.2'
- DEFAULT_KDF_ALGO =
'KDF2(SHA-256)'
- DEFAULT_KDF_SALT_LENGTH =
16
- DEFAULT_KDF_ITERATIONS =
100_000
- DEFAULT_PBKDF_ALGO =
'PBKDF2(SHA-256)'
- DEFAULT_EME =
'EME1(SHA-256)'
- DEFAULT_EMSA =
{ 'RSA' => 'EMSA4(SHA-256)', 'DSA' => 'EMSA1(SHA-256)', 'ECDSA' => 'EMSA1(SHA-256)', 'ECKCDSA' => 'EMSA1(SHA-256)', 'ECGDSA' => 'EMSA1(SHA-256)', 'GOST-34.10' => 'EMSA1(SHA-256)' }.freeze
- DEFAULT_AEAD =
'AES-256/OCB'
Class Method Summary collapse
-
.call_ffi(fn, *args) ⇒ void
private
Calls the LibBotan FFI function indicated.
-
.call_ffi_rc(fn, *args) ⇒ Integer
private
Calls the LibBotan FFI function indicated and returns the return code.
-
.call_ffi_with_buffer(fn, guess: 4096, string: false) ⇒ String
private
Calls the LibBotan FFI function indicated If the return code is <0, an error will be raised.
-
.Digest(algo) ⇒ Class
Returns a Digest subclass by name.
-
.hex_decode(hexs) ⇒ String
Decodes the provided hexadecimal string to a byte string.
-
.hex_encode(data) ⇒ String
Encodes the provided data as a hexadecimal string.
- .inspect_ptr(myself) ⇒ Object private
Class Method Details
.call_ffi(fn, *args) ⇒ void
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.
This method returns an undefined value.
Calls the LibBotan FFI function indicated. If the return code is <0, an error will be raised.
49 50 51 52 |
# File 'lib/botan/utils.rb', line 49 def self.call_ffi(fn, *args) call_ffi_rc(fn, *args) nil end |
.call_ffi_rc(fn, *args) ⇒ Integer
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.
Calls the LibBotan FFI function indicated and returns the return code. If the return code is <0, an error will be raised.
35 36 37 38 39 |
# File 'lib/botan/utils.rb', line 35 def self.call_ffi_rc(fn, *args) rc = LibBotan.method(fn).call(*args) raise Botan::Error, "FFI call to #{fn} failed (rc: #{rc})" if rc.negative? rc end |
.call_ffi_with_buffer(fn, guess: 4096, string: false) ⇒ String
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.
Calls the LibBotan FFI function indicated If the return code is <0, an error will be raised.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/botan/utils.rb', line 64 def self.call_ffi_with_buffer(fn, guess: 4096, string: false) buf = FFI::MemoryPointer.new(:uint8, guess) buf_len_ptr = FFI::MemoryPointer.new(:size_t) buf_len_ptr.write(:size_t, buf.size) rc = fn.call(buf, buf_len_ptr) buf_len = buf_len_ptr.read(:size_t) # Call should only fail if buffer was inadequate, and should # only succeed if buffer was adequate. if (rc.negative? && buf_len <= buf.size) || (rc >= 0 && buf_len > buf.size) raise Botan::Error, 'FFI call unexpectedly failed' end if rc.negative? return call_ffi_with_buffer(fn, guess: buf_len, string: string) else string ? buf.read_string : buf.read_bytes(buf_len) end end |
.Digest(algo) ⇒ Class
Returns a Digest subclass by name.
139 140 141 |
# File 'lib/botan/digest.rb', line 139 def Digest(algo) Botan::Digest.const_get(algo) end |
.hex_decode(hexs) ⇒ String
Decodes the provided hexadecimal string to a byte string.
23 24 25 |
# File 'lib/botan/utils.rb', line 23 def self.hex_decode(hexs) [hexs].pack('H*') end |
.hex_encode(data) ⇒ String
Encodes the provided data as a hexadecimal string.
15 16 17 |
# File 'lib/botan/utils.rb', line 15 def self.hex_encode(data) data.unpack('H*')[0] end |
.inspect_ptr(myself) ⇒ Object
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.
85 86 87 88 89 90 |
# File 'lib/botan/utils.rb', line 85 def self.inspect_ptr(myself) ptr_format = "0x%0#{FFI::Pointer.size * 2}x" ptr_s = format(ptr_format, myself.instance_variable_get(:@ptr).address) class_name = myself.class.to_s "#<#{class_name}:#{ptr_s}>" end |