Class: CryptBuffer
- Inherits:
-
Object
- Object
- CryptBuffer
- Extended by:
- Forwardable
- Includes:
- CryptBufferConcern::Arithmetic, CryptBufferConcern::Array, 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_base64(input) ⇒ Object
-
.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, #strip_padding!, #validate_padding!
Methods included from CryptBufferConcern::Comparable
Methods included from CryptBufferConcern::Convertable
#base64, #bits, #chars, #hex, #str, #to_crypt_buffer, #to_s
Methods included from CryptBufferConcern::Array
#+, #[], #first, #last, #shift, #unshift
Methods included from CryptBufferConcern::Arithmetic
#add, #hdist, #mod_sub, #modulus, #sub
Constructor Details
#initialize(byte_array) ⇒ CryptBuffer
Returns a new instance of CryptBuffer.
43 44 45 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 43 def initialize(byte_array) @bytes = byte_array end |
Instance Attribute Details
#bytes ⇒ Object Also known as: b
Returns the value of attribute bytes.
18 19 20 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 18 def bytes @bytes end |
Class Method Details
.from_base64(input) ⇒ Object
54 55 56 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 54 def self.from_base64(input) CryptBufferInputConverter.new.from_base64(input) end |
.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
50 51 52 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 50 def self.from_hex(input) CryptBufferInputConverter.new.from_hex(input) end |
Instance Method Details
#chunks_of(n) ⇒ Object
73 74 75 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 73 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
66 67 68 69 70 71 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 66 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
58 59 60 61 62 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 58 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 |