Class: EllipticCurve::Utils::Binary
- Inherits:
-
Object
- Object
- EllipticCurve::Utils::Binary
- Defined in:
- lib/utils/binary.rb
Class Method Summary collapse
- .base64FromByteString(byteString) ⇒ Object
- .bitsFromHex(hexadecimal) ⇒ Object
- .byteStringFromBase64(base64) ⇒ Object
- .byteStringFromHex(hexadecimal) ⇒ Object
- .hexFromByteString(bytes) ⇒ Object
- .hexFromInt(number) ⇒ Object
- .intFromHex(hexadecimal) ⇒ Object
- .numberFromByteString(bytes) ⇒ Object
Class Method Details
.base64FromByteString(byteString) ⇒ Object
31 32 33 |
# File 'lib/utils/binary.rb', line 31 def self.base64FromByteString(byteString) return Base64.encode64(byteString).gsub("\n", "") end |
.bitsFromHex(hexadecimal) ⇒ Object
39 40 41 |
# File 'lib/utils/binary.rb', line 39 def self.bitsFromHex(hexadecimal) return intFromHex(hexadecimal).to_s(2).rjust(hexadecimal.length * 4, "0") end |
.byteStringFromBase64(base64) ⇒ Object
35 36 37 |
# File 'lib/utils/binary.rb', line 35 def self.byteStringFromBase64(base64) return Base64.decode64(base64) end |
.byteStringFromHex(hexadecimal) ⇒ Object
23 24 25 |
# File 'lib/utils/binary.rb', line 23 def self.byteStringFromHex(hexadecimal) return [hexadecimal].pack("H*") end |
.hexFromByteString(bytes) ⇒ Object
19 20 21 |
# File 'lib/utils/binary.rb', line 19 def self.hexFromByteString(bytes) return bytes.unpack("H*")[0] end |
.hexFromInt(number) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/utils/binary.rb', line 7 def self.hexFromInt(number) hexadecimal = number.to_s(16) if hexadecimal.length % 2 == 1 hexadecimal = "0" + hexadecimal end return hexadecimal end |
.intFromHex(hexadecimal) ⇒ Object
15 16 17 |
# File 'lib/utils/binary.rb', line 15 def self.intFromHex(hexadecimal) return hexadecimal.to_i(16) end |
.numberFromByteString(bytes) ⇒ Object
27 28 29 |
# File 'lib/utils/binary.rb', line 27 def self.numberFromByteString(bytes) return bytes.unpack("C*").reduce(0) { |number, byte| number * 256 + byte } end |