Class: GitBlur::Crypto::CipherMgr

Inherits:
Object
  • Object
show all
Defined in:
lib/git-blur/crypto.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCipherMgr

Returns a new instance of CipherMgr.



10
11
12
13
14
15
# File 'lib/git-blur/crypto.rb', line 10

def initialize
  @ciphers = GitBlur::Conf.ciphers
  @cipher_keys = GitBlur::Conf.keys
  raise "Repo does not seem to be initialized. Please execute git veil init" if @ciphers.nil? or @cipher_keys.nil?
  @bsize = 8192
end

Instance Attribute Details

#bsizeObject

Returns the value of attribute bsize.



8
9
10
# File 'lib/git-blur/crypto.rb', line 8

def bsize
  @bsize
end

Instance Method Details

#decrypt_stream(instream, outstream = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/git-blur/crypto.rb', line 17

def decrypt_stream( instream, outstream = nil )
  outstream = $stdout if outstream.nil?
  magic = instream.read( 12 )
  if magic != "GIT-VEILFTW|"
    #Not git-blur file
    outstream.write( magic )
    while not instream.eof?
      outstream.write( instream.read( @bsize ) )
    end
    return
  end
  #READ nonce ( SHA512 length )
  nonce = instream.read( 64 )
  process_stream( instream, outstream, get_decrypters( nonce ) )
end

#encrypt_stream(instream, outstream = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/git-blur/crypto.rb', line 33

def encrypt_stream( instream, outstream = nil )
  outstream = $stdout if outstream.nil?
  nonce = OpenSSL::Digest::SHA512.new
  data = ""
  while not instream.eof?
    rb = instream.read(8192)
    nonce.update(rb)
    data += rb 
  end
  nonce = nonce.digest
  outstream.write( "GIT-VEILFTW|#{nonce}" )
  process_stream( StringIO.new( data ), outstream, get_encrypters( nonce ) )
end

#generate_iv(cname, nonce, iv_len) ⇒ Object



55
56
57
58
# File 'lib/git-blur/crypto.rb', line 55

def generate_iv( cname, nonce, iv_len )
  cnonce = "#{cname}:#{nonce.to_s}" 
  OpenSSL::Digest::SHA512.new( cnonce ).digest.slice( 1, iv_len ) 
end

#get_decrypters(nonce) ⇒ Object



60
61
62
63
64
65
# File 'lib/git-blur/crypto.rb', line 60

def get_decrypters( nonce )
  generate_cipers do |c|
    c.decrypt
    c.iv = generate_iv( c.name, nonce, c.iv_len )
  end.reverse
end

#get_encrypters(nonce) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/git-blur/crypto.rb', line 47

def get_encrypters( nonce )
  generate_cipers do |c|
    c.encrypt
    cnonce = "#{c.name}:#{nonce.to_s}" 
    c.iv = OpenSSL::Digest::SHA512.new( cnonce ).digest.slice( 1, c.iv_len ) 
  end
end