ffi-libsodium 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95a7d9bb37cc560f3dfbb7a72a6bcf31ffdf63d6
4
- data.tar.gz: 636823f16c86f508ff3180c56edb357a6b8afa2c
3
+ metadata.gz: 0b54d280d3fdd22d6572b1eed77f44a3c7566091
4
+ data.tar.gz: abdbaaa5de78cc99f1cb9a26044e5ba4514e0127
5
5
  SHA512:
6
- metadata.gz: e101ac68e41004c5b1dab8594baf37a6bd3c68fa6bb4981fdc556ef7d6d9cfac3e5aadaaec9c4ff11c524570fcf49500459aca5eed2486c8af7835235a0a5b61
7
- data.tar.gz: 9c3e394cdf2941d370ad3c690c0bf17a335ba4cc9aba9aea5fa61b88bdff986369493be2348aa3d6663fff6e6e98c3aa6901d5fbefd5b59a5d3893f5bc696fa1
6
+ metadata.gz: 2ead290d9a7cfdc44bf9184d5ac2245e9af185d53d7ce34588afa63b7438204a53521b43a136ed394bfe6193d68949932d7656fa1a1fdc8cf0a71bd3f88435fd
7
+ data.tar.gz: 6e9dedb63914e6287f3ba27f5a3d6a970a04f0c297f60ee6938831cbe58b979fa75c7660bc9c3d37b0f47d13729a8a1abc2a29580cd07aaa5a909a72f086f696
@@ -130,7 +130,7 @@ module Crypto
130
130
  secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
131
131
  end
132
132
 
133
- def open_easy_in_place(data, nonce, public_key, secret_key, encoding = false)
133
+ def open_easy_in_place(data, nonce, public_key, secret_key, encoding = nil)
134
134
  ciphertext = String(data)
135
135
  ciphertext_len = ciphertext.bytesize
136
136
  if (message_len = ciphertext_len - MACBYTES) > 0
@@ -76,7 +76,7 @@ module Crypto
76
76
  key.noaccess if key.is_a?(Sodium::SecretBuffer)
77
77
  end
78
78
 
79
- def open_easy_in_place(data, nonce, key, encoding = false)
79
+ def open_easy_in_place(data, nonce, key, encoding = nil)
80
80
  ciphertext = String(data)
81
81
  ciphertext_len = ciphertext.bytesize
82
82
  if (message_len = ciphertext_len - MACBYTES) > 0
@@ -1,4 +1,5 @@
1
- require_relative 'sodium/errors'
1
+ require_relative 'sodium/core_ext'
2
+ require_relative 'sodium/errors'
2
3
  require_relative 'sodium'
3
4
  require_relative 'sodium/utils'
4
5
  require_relative 'sodium/buffer'
@@ -1,7 +1,5 @@
1
1
  require 'ffi'
2
2
  require_relative 'sodium/errors'
3
- require_relative 'sodium/utils'
4
- require_relative 'sodium/buffer'
5
3
 
6
4
  module Sodium
7
5
  extend FFI::Library
@@ -0,0 +1,5 @@
1
+ class NilClass
2
+ def size
3
+ 0
4
+ end
5
+ end
@@ -1,6 +1,5 @@
1
1
  require 'ffi'
2
2
  require_relative 'errors'
3
- require_relative 'utils'
4
3
 
5
4
  module Sodium
6
5
  module Mprotect
@@ -1,5 +1,4 @@
1
- require 'ffi'
2
- require_relative 'secret_buffer'
1
+ require_relative 'core_ext'
3
2
  require_relative 'errors'
4
3
 
5
4
  module Sodium
@@ -8,34 +7,18 @@ module Sodium
8
7
  module_function
9
8
 
10
9
  def get_size(data)
11
- case data
12
- when FFI::Pointer, SecretBuffer
13
- data.size
14
- when String
10
+ if data.respond_to?(:bytesize)
15
11
  data.bytesize
16
- when NilClass
17
- 0
18
12
  else
19
- fail TypeError, "#{data.class} must be of type FFI::Pointer, Sodium::SecretBufffer, String or NilClass", caller
13
+ data.size
20
14
  end
21
15
  end
22
16
 
23
17
  def check_length(data, length, description)
24
- case data
25
- when FFI::Pointer, SecretBuffer
26
- if data.size == length
27
- true
28
- else
29
- fail LengthError, "Expected a length=#{length} bytes #{description}, got size=#{data.size} bytes", caller
30
- end
31
- when String
32
- if data.bytesize == length
33
- true
34
- else
35
- fail LengthError, "Expected a length=#{length} bytes #{description}, got size=#{data.bytesize} bytes", caller
36
- end
18
+ if data.respond_to?(:bytesize)
19
+ data.bytesize == length || fail(LengthError, "Expected a length=#{length} bytes #{description}, got size=#{data.bytesize} bytes", caller)
37
20
  else
38
- fail TypeError, "#{data.class} must be of type FFI::Pointer, Sodium::SecretBufffer or String", caller
21
+ data.size == length || fail(LengthError, "Expected a length=#{length} bytes #{description}, got size=#{data.size} bytes", caller)
39
22
  end
40
23
  end
41
24
 
@@ -48,11 +31,11 @@ module Sodium
48
31
  HEXY = 'H*'.freeze
49
32
 
50
33
  def bin2hex(bytes)
51
- bytes.to_str.unpack(HEXY).first
34
+ String(bytes).unpack(HEXY).first
52
35
  end
53
36
 
54
37
  def hex2bin(hex)
55
- [hex].pack(HEXY)
38
+ [String(hex)].pack(HEXY)
56
39
  end
57
40
  end
58
41
 
@@ -1,3 +1,3 @@
1
1
  module Sodium
2
- VERSION = Gem::Version.new('0.2.0')
2
+ VERSION = Gem::Version.new('0.2.1')
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-libsodium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hendrik Beskow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-15 00:00:00.000000000 Z
11
+ date: 2014-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -61,6 +61,7 @@ files:
61
61
  - lib/random_bytes.rb
62
62
  - lib/sodium.rb
63
63
  - lib/sodium/buffer.rb
64
+ - lib/sodium/core_ext.rb
64
65
  - lib/sodium/errors.rb
65
66
  - lib/sodium/mprotect.rb
66
67
  - lib/sodium/secret_buffer.rb