Class: Browser::Crypto::Digest

Inherits:
Object
  • Object
show all
Defined in:
opal/browser/crypto.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bufferObject (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_b64Object

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_hexObject

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_sObject

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