Class: Dommy::CryptoKey

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/crypto.rb

Overview

‘CryptoKey` — opaque key handle returned by SubtleCrypto. `extractable: false` keys reject export attempts; the `__bytes__` accessor stays internal-only (`double_underscore` convention) so production code paths can’t read the raw bytes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, algorithm_name, hash_name, bytes, extractable: true, usages: []) ⇒ CryptoKey

Returns a new instance of CryptoKey.



368
369
370
371
372
373
374
375
# File 'lib/dommy/crypto.rb', line 368

def initialize(type, algorithm_name, hash_name, bytes, extractable: true, usages: [])
  @type = type
  @algorithm_name = algorithm_name
  @hash_name = hash_name
  @bytes = bytes
  @extractable = extractable
  @usages = usages.map(&:to_s).freeze
end

Instance Attribute Details

#algorithm_nameObject (readonly)

Returns the value of attribute algorithm_name.



366
367
368
# File 'lib/dommy/crypto.rb', line 366

def algorithm_name
  @algorithm_name
end

#extractableObject (readonly)

Returns the value of attribute extractable.



366
367
368
# File 'lib/dommy/crypto.rb', line 366

def extractable
  @extractable
end

#hash_nameObject (readonly)

Returns the value of attribute hash_name.



366
367
368
# File 'lib/dommy/crypto.rb', line 366

def hash_name
  @hash_name
end

#typeObject (readonly)

Returns the value of attribute type.



366
367
368
# File 'lib/dommy/crypto.rb', line 366

def type
  @type
end

#usagesObject (readonly)

Returns the value of attribute usages.



366
367
368
# File 'lib/dommy/crypto.rb', line 366

def usages
  @usages
end

Instance Method Details

#__bytes__Object

Test / internal seam — production callers should not reach in.



378
379
380
# File 'lib/dommy/crypto.rb', line 378

def __bytes__
  @bytes
end

#__js_get__(key) ⇒ Object



382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/dommy/crypto.rb', line 382

def __js_get__(key)
  case key
  when "type"
    @type.to_s
  when "extractable"
    @extractable
  when "algorithm"
    {"name" => @algorithm_name, "hash" => {"name" => @hash_name}}
  when "usages"
    @usages
  end
end