class Rmega::Nodes::NodeKey

The key associated to a node. It can be 128 or 256 bits long, when is 256 bits long is composed by:

Attributes

aes_key[R]
ctr_nonce[R]
meta_mac[RW]

Public Class Methods

compact(string) click to toggle source
# File lib/rmega/nodes/node_key.rb, line 30
def self.compact(string)
  if string.size > 16
    bytes = string.bytes.to_a
    return 16.times.inject([]) { |ary, i| ary[i] = bytes[i] ^ bytes[i+16]; ary }.map(&:chr).join
  else
    return string
  end
end
load(string) click to toggle source

note: folder key is 16 bytes long while file key is 32

# File lib/rmega/nodes/node_key.rb, line 26
def self.load(string)
  new("#{compact(string)}#{string[16..-1]}")
end
new(string) click to toggle source
# File lib/rmega/nodes/node_key.rb, line 15
def initialize(string)
  @aes_key   = string[0..15]
  @ctr_nonce = string[16..23]
  @meta_mac  = string[24..31]
end
random() click to toggle source
# File lib/rmega/nodes/node_key.rb, line 39
def self.random
  new(OpenSSL::Random.random_bytes(16 + 8 + 0))
end

Public Instance Methods

generate() click to toggle source
# File lib/rmega/nodes/node_key.rb, line 21
def generate
  self.class.compact("#{@aes_key}#{@ctr_nonce}#{@meta_mac}") + @ctr_nonce + @meta_mac
end