Class: Cryptosphere::Blob
- Inherits:
-
Object
- Object
- Cryptosphere::Blob
- Defined in:
- lib/cryptosphere/blobs/blob.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Builder
Constant Summary collapse
- PREFIX =
Prefix added to the beginning of every Cryptosphere node
"blob::"
Class Attribute Summary collapse
-
.path ⇒ Object
readonly
Returns the value of attribute path.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.[](obj) ⇒ Object
Create a node from a given object.
-
.setup(options = {}) ⇒ Object
Configure the Cryptosphere Node store.
Instance Method Summary collapse
- #decrypt ⇒ Object
-
#initialize(id, key) ⇒ Blob
constructor
A new instance of Blob.
Constructor Details
#initialize(id, key) ⇒ Blob
Returns a new instance of Blob.
38 39 40 41 |
# File 'lib/cryptosphere/blobs/blob.rb', line 38 def initialize(id, key) @id, @key = id, key @path = File.join(self.class.path, @id) end |
Class Attribute Details
.path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/cryptosphere/blobs/blob.rb', line 12 def path @path end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/cryptosphere/blobs/blob.rb', line 9 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/cryptosphere/blobs/blob.rb', line 9 def key @key end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/cryptosphere/blobs/blob.rb', line 9 def path @path end |
Class Method Details
.[](obj) ⇒ Object
Create a node from a given object
31 32 33 34 35 |
# File 'lib/cryptosphere/blobs/blob.rb', line 31 def [](obj) builder = Builder.new builder << obj builder.finish end |
.setup(options = {}) ⇒ Object
Configure the Cryptosphere Node store
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cryptosphere/blobs/blob.rb', line 15 def setup( = {}) unless [:root] raise ArgumentError, "no :root path given" end unless File.directory? [:root] raise ArgumentError, "no such directory: #{[:root]}" end @path = File.("nodes", [:root]) FileUtils.mkdir @path unless File.directory? @path nil end |
Instance Method Details
#decrypt ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cryptosphere/blobs/blob.rb', line 43 def decrypt raise "can't decrypt node without key" unless @key cipher = Cryptosphere.block_cipher cipher.decrypt cipher.key = @key[0...32] cipher.iv = @key[32...64] output = '' File.open(@path, 'r') do |file| while data = file.read(4096) output << cipher.update(data) end end output << cipher.final end |