Class: Browser::Crypto::Digest
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Instance Method Summary collapse
-
#initialize(buf) ⇒ Digest
constructor
A new instance of Digest.
-
#to_b64 ⇒ Object
Convert a digest to a Base64-encoded string.
-
#to_hex ⇒ Object
Convert a digest to a hexadecimal string.
-
#to_s ⇒ Object
Convert a digest to a binary string.
-
#to_u64(padding: false) ⇒ Object
Convert a digest to a urlsafe Base64-encoded string.
Constructor Details
#initialize(buf) ⇒ Digest
Returns a new instance of Digest.
10 11 12 |
# File 'opal/browser/crypto.rb', line 10 def initialize(buf) @buffer = Buffer.new(buf) end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
14 15 16 |
# File 'opal/browser/crypto.rb', line 14 def buffer @buffer end |
Instance Method Details
#to_b64 ⇒ Object
Convert a digest to a Base64-encoded string
You will need to require "base64"
29 30 31 |
# File 'opal/browser/crypto.rb', line 29 def to_b64 Base64.strict_encode64(to_s) end |
#to_hex ⇒ Object
Convert a digest to a hexadecimal string
17 18 19 |
# File 'opal/browser/crypto.rb', line 17 def to_hex buffer.to_a.map { |i| "%02x" % i }.join end |
#to_s ⇒ Object
Convert a digest to a binary string
22 23 24 |
# File 'opal/browser/crypto.rb', line 22 def to_s buffer.to_a.map { |i| "%c" % i }.join end |
#to_u64(padding: false) ⇒ Object
Convert a digest to a urlsafe Base64-encoded string
You will need to require "base64"
36 37 38 |
# File 'opal/browser/crypto.rb', line 36 def to_u64(padding: false) Base64.urlsafe_encode64(to_s, padding: padding) end |