13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/ruar/serialize.rb', line 13
def self.aead(srcdir, dstfile)
time = Time.now.strftime('%Y%m%dT%H%M')
tmpdir = File.expand_path("ruar_#{time}", Dir.tmpdir)
FileUtils.copy_entry(srcdir, tmpdir)
encryption_info = nil
index = Ruar::Index.new(tmpdir) do |file|
data = File.read(file)
encryption_info = Ruar.cipher.encrypt(data)
File.write(file, encryption_info[:encrypted])
end
encrypted_index = Ruar.cipher.encrypt(index.json_index)[:encrypted]
Ruar::Serialize::Native.(dstfile, encrypted_index)
index.source_info.each do |src|
Ruar::Serialize::Native.append_file(dstfile, src['realpath'])
end
setup_file = " Ruar.cipher.setup(\n iv: '\#{Base64.encode64(encryption_info[:iv]).chomp}',\n key: '\#{Base64.encode64(encryption_info[:key]).chomp}',\n auth_data: '\#{Base64.encode64(encryption_info[:auth_data]).chomp}',\n tag: '\#{Base64.encode64(encryption_info[:tag]).chomp}')\n Ruar.cipher.enable\n SETUP\n\n File.write(\"\#{dstfile}.setup\", setup_file)\n\n FileUtils.rm_rf(tmpdir)\nend\n"
|