ffi-libsodium 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sodium.rb +25 -12
  3. data/lib/sodium/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87db0771703338d8f1f2af7e6e0b4fa97bf16340
4
- data.tar.gz: 5362403aea2592d3b09b56f2051ea93424635d57
3
+ metadata.gz: 098cc9a2b79fd39389f77241c75bc2e03efb0461
4
+ data.tar.gz: e1ae4db97427751f2eb56d9081c30a3a7791604b
5
5
  SHA512:
6
- metadata.gz: 8c87f61dc009dd14d49f18d78a9f7f50ead03d972b0d08e87bc7f81d2c6b2e4cc66234e6402cf57f231607ada0ba0f01c0b4b0bb6a63cd213df4e21afdf16678
7
- data.tar.gz: 33d8c50b5575fc148f215f26f1cd108fd4dbebfef6a7c4a613bd465e944652b1d0d746baefeaa7dadc3b7f54790bef7e84ef7c159455cc0358be7c8d3a824db7
6
+ metadata.gz: be3aa678237413491b999b89dc66d93a4567fed6a01be67e197844f92e4aa9dc4e3a58dc506eac54731ab117ca5501e04caa665332902477531e3fb6a097195a
7
+ data.tar.gz: 15f1532694c26a4b2ec4bd04c64c25805e1f9c9a9d688aee75b1ac92142876a7ab4cd8bbd483a869375b36eda66429e82f3e680e5f663df752a60625283a7a75
data/lib/sodium.rb CHANGED
@@ -24,19 +24,35 @@ module Sodium
24
24
  module_function
25
25
 
26
26
  def mlock(addr, len)
27
- sodium_mlock(addr, len) == 0 || raise(MemoryError, "Could not lock length=#{len} bytes memory at address=#{addr.address}", caller)
27
+ if sodium_mlock(addr, len) == 0
28
+ true
29
+ else
30
+ raise MemoryError, "Could not lock length=#{len} bytes memory at address=#{addr.address}", caller
31
+ end
28
32
  end
29
33
 
30
34
  def munlock(addr, len)
31
- sodium_munlock(addr, len) == 0 || raise(MemoryError, "Could not unlock length=#{len} bytes memory at address=#{addr.address}", caller)
35
+ if sodium_munlock(addr, len) == 0
36
+ true
37
+ else
38
+ raise MemoryError, "Could not unlock length=#{len} bytes memory at address=#{addr.address}", caller
39
+ end
32
40
  end
33
41
 
34
42
  def malloc(size)
35
- sodium_malloc(size) || raise(NoMemoryError, "Failed to allocate memory size=#{size} bytes", caller)
43
+ unless (mem = sodium_malloc(size)).null?
44
+ mem
45
+ else
46
+ raise NoMemoryError, "Failed to allocate memory size=#{size} bytes", caller
47
+ end
36
48
  end
37
49
 
38
50
  def allocarray(count, size)
39
- sodium_allocarray(count, size) || raise(NoMemoryError, "Failed to allocate memory size=#{count * size} bytes", caller)
51
+ unless (mem = sodium_allocarray(count, size)).null?
52
+ mem
53
+ else
54
+ raise NoMemoryError, "Failed to allocate memory size=#{count * size} bytes", caller
55
+ end
40
56
  end
41
57
 
42
58
  def bin2hex(bin)
@@ -45,15 +61,12 @@ module Sodium
45
61
  sodium_bin2hex(hex, hex.size, bin, bin_len)
46
62
  end
47
63
 
48
- def hex2bin(hex, ignore = nil)
49
- if ignore
50
- bin_maxlen = hex.tr(ignore, '').bytesize / 2
64
+ def hex2bin(hex, bin_maxlen, ignore = nil)
65
+ bin = Sodium::Buffer.new(:uchar, bin_maxlen)
66
+ if sodium_hex2bin(bin, bin_maxlen, hex, hex.bytesize, ignore, nil, nil) == 0
67
+ bin
51
68
  else
52
- bin_maxlen = hex.bytesize / 2
69
+ raise LengthError, "bin_maxlen=#{bin_maxlen} is too short", caller
53
70
  end
54
-
55
- bin = Sodium::Buffer.new(:uchar, bin_maxlen)
56
- sodium_hex2bin(bin, bin_maxlen, hex, hex.bytesize, ignore, nil, nil)
57
- bin
58
71
  end
59
72
  end
@@ -1,3 +1,3 @@
1
1
  module Sodium
2
- VERSION = Gem::Version.new('0.2.4')
2
+ VERSION = Gem::Version.new('0.2.5')
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.4
4
+ version: 0.2.5
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-20 00:00:00.000000000 Z
11
+ date: 2014-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi