Class: CryptBuffer
- Inherits:
-
Object
- Object
- CryptBuffer
- Extended by:
- Forwardable
- Includes:
- CryptBufferConcern::Arithmetic, CryptBufferConcern::ByteExpander, CryptBufferConcern::Comparable, CryptBufferConcern::Convertable, CryptBufferConcern::Padding, CryptBufferConcern::PrettyPrint, CryptBufferConcern::Random, CryptBufferConcern::Xor, Enumerable
- Defined in:
- lib/crypto-toolbox/crypt_buffer.rb
Defined Under Namespace
Classes: OutOfRangeError
Instance Attribute Summary collapse
-
#bytes ⇒ Object
(also: #b)
Returns the value of attribute bytes.
Class Method Summary collapse
-
.from_hex(input) ⇒ Object
Make sure input strings are always interpreted as hex strings This is especially useful for unknown or uncertain inputs like strings with or without leading 0x.
Instance Method Summary collapse
- #chunks_of(n) ⇒ Object
-
#initialize(byte_array) ⇒ CryptBuffer
constructor
A new instance of CryptBuffer.
-
#nth_bits(n) ⇒ Object
Returns an array of the nth least sigificant by bit of each byte.
- #nth_bytes(n, offset: 0) ⇒ Object
Methods included from CryptBufferConcern::Xor
#xor, #xor_all_with, #xor_at, #xor_space
Methods included from CryptBufferConcern::Random
Methods included from CryptBufferConcern::PrettyPrint
Methods included from CryptBufferConcern::Padding
#pad, #padding, #padding?, #strip_padding
Methods included from CryptBufferConcern::Comparable
Methods included from CryptBufferConcern::Convertable
#bits, #chars, #hex, #str, #to_s
Methods included from CryptBufferConcern::Arithmetic
#add, #mod_sub, #modulus, #sub
Constructor Details
#initialize(byte_array) ⇒ CryptBuffer
Returns a new instance of CryptBuffer.
36 37 38 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 36 def initialize(byte_array) @bytes = byte_array end |
Instance Attribute Details
#bytes ⇒ Object Also known as: b
Returns the value of attribute bytes.
32 33 34 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 32 def bytes @bytes end |
Class Method Details
.from_hex(input) ⇒ Object
Make sure input strings are always interpreted as hex strings This is especially useful for unknown or uncertain inputs like strings with or without leading 0x
43 44 45 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 43 def self.from_hex(input) CryptBufferInputConverter.new.from_hex(input) end |
Instance Method Details
#chunks_of(n) ⇒ Object
62 63 64 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 62 def chunks_of(n) self.bytes.each_slice(n).map{|chunk| CryptBuffer(chunk) } end |
#nth_bits(n) ⇒ Object
Returns an array of the nth least sigificant by bit of each byte
55 56 57 58 59 60 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 55 def nth_bits(n) raise OutOfRangeError if n < 0 raise OutOfRangeError if n > 7 bits.map{|b| b.reverse[n].to_i } end |
#nth_bytes(n, offset: 0) ⇒ Object
47 48 49 50 51 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 47 def nth_bytes(n,offset: 0) return CryptBuffer([]) if n.nil? || n < 1 CryptBuffer((0+offset).step(length,n).map{|i| bytes[i] }.compact) end |