Module: Rmega::Nodes::Expandable

Includes:
Uploadable
Included in:
Folder, Root
Defined in:
lib/rmega/nodes/expandable.rb

Instance Method Summary collapse

Methods included from Uploadable

#encrypt_chunck, #read_chunk, #upload, #upload_chunk

Methods included from Rmega::Net

#http_get_content, #http_post, #survive

Methods included from Options

#options

Methods included from Loggable

#logger

Instance Method Details

#create_folder(name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rmega/nodes/expandable.rb', line 6

def create_folder(name)
  node_key = NodeKey.random

  # encrypt attributes
  attributes_str = "MEGA"
  attributes_str << {n: name.strip}.to_json
  attributes_str << ("\x00" * (16 - (attributes_str.size % 16)))
  encrypted_attributes = aes_cbc_encrypt(node_key.aes_key, attributes_str)

  # Encrypt node key
  encrypted_key = aes_ecb_encrypt(session.master_key, node_key.aes_key)

  n = [{h: 'xxxxxxxx', t: 1, a: Utils.base64urlencode(encrypted_attributes), k: Utils.base64urlencode(encrypted_key)}]
  data = session.request(a: 'p', t: handle, n: n)
  return Folder.new(session, data['f'][0])
end

#upload_url(filesize) ⇒ Object



23
24
25
# File 'lib/rmega/nodes/expandable.rb', line 23

def upload_url(filesize)
  session.request(a: 'u', s: filesize)['p']
end