class Noteshred::Note
Constants
- SHRED_AFTER_READING
Shred Methods
- SHRED_LATER
Attributes
content[RW]
encrypted_content[RW]
encrypted_content_iv[RW]
encrypted_content_salt[RW]
hint[RW]
password[RW]
password_hash[RW]
recipients[RW]
shred_by[RW]
shred_method[RW]
title[RW]
version[RW]
Public Class Methods
Public Instance Methods
create()
click to toggle source
# File lib/noteshred/note.rb, line 21 def create # For creating notes that are encrypted on the server validate_content validate_options Noteshred::API.post('/notes', Noteshred::Tools.hashify(self)) end
decrypt()
click to toggle source
# File lib/noteshred/note.rb, line 60 def decrypt validate_encrypted_content self.content = Noteshred::Crypto::V4.decrypt(self.encrypted_content, self.password, self.encrypted_content_salt, self.encrypted_content_iv) self.encrypted_content_iv = nil self.encrypted_content_salt = nil self.encrypted_content = nil self.password_hash = nil return self end
encrypt()
click to toggle source
# File lib/noteshred/note.rb, line 47 def encrypt validate_content crypt = Noteshred::Crypto::V4.encrypt(self.content, self.password) self.encrypted_content = crypt[:content] self.encrypted_content_iv = crypt[:iv] self.encrypted_content_salt = crypt[:salt] self.version = crypt[:version] self.password_hash = BCrypt::Password.create(self.password) self.content = nil self.password = nil return self end
pull(token,pass)
click to toggle source
# File lib/noteshred/note.rb, line 38 def pull(token,pass) # For pulling raw encrypted notes from the server # TODO: Implement server side portion if token.nil? || password.nil? raise ArgumentError.new('token and password params are required') end Noteshred::API.get('/notes/pull', {:password => pass, :token => token}) end
push()
click to toggle source
# File lib/noteshred/note.rb, line 28 def push # For creating notes that are encrypted by the gem first then pushed to the server validate_options if self.encrypted_content_salt.nil? || encrypted_content_iv.nil? raise ArgumentError.new('No encrypted content found. Must call .encrypt before pushing') end Noteshred::API.post('/notes/push', Noteshred::Tools.hashify(self)) end
Private Instance Methods
validate_content()
click to toggle source
# File lib/noteshred/note.rb, line 83 def validate_content raise ArgumentError.new('Missing Password') if password.nil? raise ArgumentError.new('Password Must Be Minimum 8 Characters') if password.size < 8 raise ArgumentError.new('Missing Content') if content.nil? end
validate_encrypted_content()
click to toggle source
# File lib/noteshred/note.rb, line 89 def validate_encrypted_content raise ArgumentError.new('Missing Password') if password.nil? raise ArgumentError.new('Missing Content') if encrypted_content.nil? raise ArgumentError.new('Missing Salt') if encrypted_content_salt.nil? end
validate_options()
click to toggle source
# File lib/noteshred/note.rb, line 95 def validate_options raise ArgumentError.new('shred_by date not set') if shred_method == SHRED_LATER && shred_by.nil? if !recipients.nil? raise ArgumentError.new('recipients must be an array.') unless recipients.kind_of?(Array) end if self.shred_method.nil? self.shred_method = SHRED_AFTER_READING end end