Class: Bitferry::Rclone::Encryption

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

Direct Known Subclasses

Decrypt, Encrypt

Constant Summary collapse

PROCESS =
{
  default: ['--crypt-filename-encoding', :base32, '--crypt-filename-encryption', :standard],
  extended: ['--crypt-filename-encoding', :base32768, '--crypt-filename-encryption', :standard]
}
ROUTE =
{
  encrypt: Rclone::Encrypt,
  decrypt: Rclone::Decrypt
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, process: nil) ⇒ Encryption

Returns a new instance of Encryption.



670
671
672
673
# File 'lib/bitferry.rb', line 670

def initialize(token, process: nil)
  @process_options = Bitferry.optional(process, PROCESS)
  @token = token
end

Class Method Details

.new(*args, **opts) ⇒ Object



704
705
706
707
708
# File 'lib/bitferry.rb', line 704

def self.new(*args, **opts)
  obj = allocate
  obj.send(:create, *args, **opts)
  obj
end

.restore(hash) ⇒ Object



711
712
713
714
715
# File 'lib/bitferry.rb', line 711

def self.restore(hash)
  obj = ROUTE.fetch(hash.fetch(:operation).intern).allocate
  obj.send(:restore, hash)
  obj
end

Instance Method Details

#arguments(task) ⇒ Object



691
# File 'lib/bitferry.rb', line 691

def arguments(task) = process_options + ['--crypt-remote', encrypted(task).root.to_s]

#configure(task) ⇒ Object



685
# File 'lib/bitferry.rb', line 685

def configure(task) = install_token(task)

#create(password, **opts) ⇒ Object



676
# File 'lib/bitferry.rb', line 676

def create(password, **opts) = initialize(Rclone.obscure(password), **opts)

#externalizeObject



682
# File 'lib/bitferry.rb', line 682

def externalize = process_options.empty? ? {} : { rclone: process_options }

#install_token(task) ⇒ Object

Raises:

  • (TypeError)


694
695
696
697
698
# File 'lib/bitferry.rb', line 694

def install_token(task)
  x = decrypted(task)
  raise TypeError, 'unsupported unencrypted endpoint type' unless x.is_a?(Endpoint::Bitferry)
  Volume[x.volume_tag].vault[task.tag] = @token # Token is stored on the decrypted end only
end

#obtain_token(task) ⇒ Object



701
# File 'lib/bitferry.rb', line 701

def obtain_token(task) = Volume[decrypted(task).volume_tag].vault.fetch(task.tag)

#process(task) ⇒ Object



688
# File 'lib/bitferry.rb', line 688

def process(task) = ENV['RCLONE_CRYPT_PASSWORD'] = obtain_token(task)

#process_optionsObject

As a mandatory option it should never be nil



667
# File 'lib/bitferry.rb', line 667

def process_options = @process_options.nil? ? [] : @process_options # As a mandatory option it should never be nil

#restore(hash) ⇒ Object



679
# File 'lib/bitferry.rb', line 679

def restore(hash) = @process_options = hash[:rclone]