rnp 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +5 -0
- data/lib/rnp/error.rb +6 -0
- data/lib/rnp/ffi/librnp.rb +37 -0
- data/lib/rnp/key.rb +51 -0
- data/lib/rnp/misc.rb +77 -0
- data/lib/rnp/output.rb +8 -0
- data/lib/rnp/rnp.rb +7 -14
- data/lib/rnp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3334282a18758db4c39bec6a7b3e3096fe4dadf85d3a8382ec780bd2a816371e
|
4
|
+
data.tar.gz: 0a1b13c36fdc0c5479e2a4531355291867481e7d1ec40bf1ec251eeb49a27cef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e41f0d9936b9b39c0646d80c6ef385aa658afe247a035a72b7005ec706fafcdfb1ffd9cf3c0f9cdad616ec12e97c0a4417460f693e71c5f56ac9942321ef5d6b
|
7
|
+
data.tar.gz: c19e9f0d2775572ac817da0f1754c057ee9281f6bb209404c1a91505532fac0a1474786dd29e73a4c9454afa8bb534b61dab80b0645127f42d7b22e23fa65594
|
data/CHANGELOG.adoc
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
== Changelog
|
2
2
|
|
3
|
+
=== 1.0.3 [08-21-2018]
|
4
|
+
* Added support for key exporting.
|
5
|
+
* Added support for enarmoring/dearmoring arbitrary data.
|
6
|
+
* Added support to retreive the rnp version.
|
7
|
+
|
3
8
|
=== 1.0.2 [08-14-2018]
|
4
9
|
* Support for newer rnp library naming (librnp-0).
|
5
10
|
|
data/lib/rnp/error.rb
CHANGED
@@ -18,6 +18,12 @@ class Rnp
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
class FeatureNotAvailableError < Error
|
22
|
+
def initialize(feature)
|
23
|
+
super("#{feature} is not available in your version of rnp.")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
21
27
|
class BadPasswordError < Error; end
|
22
28
|
class InvalidSignatureError < Error; end
|
23
29
|
class BadFormatError < Error; end
|
data/lib/rnp/ffi/librnp.rb
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
|
5
5
|
require 'ffi'
|
6
6
|
|
7
|
+
require 'rnp/error'
|
8
|
+
|
7
9
|
# @api private
|
8
10
|
module LibRnp
|
9
11
|
extend FFI::Library
|
@@ -287,6 +289,41 @@ module LibRnp
|
|
287
289
|
%i[pointer],
|
288
290
|
:uint32
|
289
291
|
|
292
|
+
# some newer APIs that may not be present
|
293
|
+
{
|
294
|
+
# key export
|
295
|
+
rnp_key_export: [%i[pointer pointer uint32], :uint32],
|
296
|
+
# enarmor/dearmor
|
297
|
+
rnp_enarmor: [%i[pointer pointer pointer], :uint32],
|
298
|
+
rnp_dearmor: [%i[pointer pointer], :uint32],
|
299
|
+
# versioning
|
300
|
+
rnp_version_string: [%i[], :string],
|
301
|
+
rnp_version_string_full: [%i[], :string],
|
302
|
+
rnp_version: [%i[], :uint32],
|
303
|
+
rnp_version_for: [%i[uint32 uint32 uint32], :uint32],
|
304
|
+
rnp_version_major: [%i[uint32], :uint32],
|
305
|
+
rnp_version_minor: [%i[uint32], :uint32],
|
306
|
+
rnp_version_patch: [%i[uint32], :uint32]
|
307
|
+
}.each do |name, signature|
|
308
|
+
present = ffi_libraries[0].find_function(name.to_s)
|
309
|
+
if !present
|
310
|
+
class_eval do
|
311
|
+
define_singleton_method(name) do |*|
|
312
|
+
raise Rnp::FeatureNotAvailableError, name
|
313
|
+
end
|
314
|
+
end
|
315
|
+
else
|
316
|
+
attach_function name, signature[0], signature[1]
|
317
|
+
end
|
318
|
+
class_eval do
|
319
|
+
const_set("HAVE_#{name.upcase}", present)
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
RNP_KEY_EXPORT_ARMORED = (1 << 0)
|
324
|
+
RNP_KEY_EXPORT_PUBLIC = (1 << 1)
|
325
|
+
RNP_KEY_EXPORT_SECRET = (1 << 2)
|
326
|
+
RNP_KEY_EXPORT_SUBKEYS = (1 << 3)
|
290
327
|
|
291
328
|
RNP_LOAD_SAVE_PUBLIC_KEYS = (1 << 0)
|
292
329
|
RNP_LOAD_SAVE_SECRET_KEYS = (1 << 1)
|
data/lib/rnp/key.rb
CHANGED
@@ -182,6 +182,48 @@ class Rnp
|
|
182
182
|
bool_property(:rnp_key_have_secret)
|
183
183
|
end
|
184
184
|
|
185
|
+
# Export a public key.
|
186
|
+
#
|
187
|
+
# By default, when exporting a primary key, only the primary key
|
188
|
+
# will be exported. When exporting a subkey, the primary key and
|
189
|
+
# subkey will both be exported.
|
190
|
+
#
|
191
|
+
# @param output [Output] the output to write the exported key.
|
192
|
+
# If nil, the result will be returned directly as a String.
|
193
|
+
# @param armored (see Sign#armored=)
|
194
|
+
# @param with_subkeys [Boolean] when exporting a primary key,
|
195
|
+
# this controls whether all subkeys should also be exported.
|
196
|
+
# When true, the primary key and all subkeys will be exported.
|
197
|
+
# When false, only the primary key will be exported.
|
198
|
+
# This parameter is not valid when the key is a subkey.
|
199
|
+
# @return [nil, String]
|
200
|
+
def export_public(armored: true, with_subkeys: false, output: nil)
|
201
|
+
Output.default(output) do |output_|
|
202
|
+
export(public_key: true, with_subkeys: with_subkeys, armored: armored, output: output_)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# Export a secret key.
|
207
|
+
#
|
208
|
+
# By default, when exporting a primary key, only the primary key
|
209
|
+
# will be exported. When exporting a subkey, the primary key and
|
210
|
+
# subkey will both be exported.
|
211
|
+
#
|
212
|
+
# @param output [Output] the output to write the exported key.
|
213
|
+
# If nil, the result will be returned directly as a String.
|
214
|
+
# @param armored (see Sign#armored=)
|
215
|
+
# @param with_subkeys [Boolean] when exporting a primary key,
|
216
|
+
# this controls whether all subkeys should also be exported.
|
217
|
+
# When true, the primary key and all subkeys will be exported.
|
218
|
+
# When false, only the primary key will be exported.
|
219
|
+
# This parameter is not valid when the key is a subkey.
|
220
|
+
# @return [nil, String]
|
221
|
+
def export_secret(armored: true, with_subkeys: false, output: nil)
|
222
|
+
Output.default(output) do |output_|
|
223
|
+
export(secret_key: true, with_subkeys: with_subkeys, armored: armored, output: output_)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
185
227
|
# Returns the raw public key data as PGP packets.
|
186
228
|
#
|
187
229
|
# @return [String]
|
@@ -270,6 +312,15 @@ class Rnp
|
|
270
312
|
end
|
271
313
|
end
|
272
314
|
end
|
315
|
+
|
316
|
+
def export(public_key: false, secret_key: false, with_subkeys: false, armored: true, output: nil)
|
317
|
+
flags = 0
|
318
|
+
flags |= LibRnp::RNP_KEY_EXPORT_ARMORED if armored
|
319
|
+
flags |= LibRnp::RNP_KEY_EXPORT_PUBLIC if public_key
|
320
|
+
flags |= LibRnp::RNP_KEY_EXPORT_SECRET if secret_key
|
321
|
+
flags |= LibRnp::RNP_KEY_EXPORT_SUBKEYS if with_subkeys
|
322
|
+
Rnp.call_ffi(:rnp_key_export, @ptr, output.ptr, flags)
|
323
|
+
end
|
273
324
|
end # class
|
274
325
|
end # class
|
275
326
|
|
data/lib/rnp/misc.rb
CHANGED
@@ -67,5 +67,82 @@ class Rnp
|
|
67
67
|
LibRnp.rnp_buffer_destroy(pformat)
|
68
68
|
end
|
69
69
|
end
|
70
|
+
|
71
|
+
# Add ASCII Armor to data.
|
72
|
+
#
|
73
|
+
# @param input [Input] the input to read data from
|
74
|
+
# @param output [Output] the output to write the armored
|
75
|
+
# data to. If nil, the result will be returned directly
|
76
|
+
# as a String.
|
77
|
+
# @return [nil, String]
|
78
|
+
def self.enarmor(input:, output: nil, type: nil)
|
79
|
+
Output.default(output) do |output_|
|
80
|
+
Rnp.call_ffi(:rnp_enarmor, input.ptr, output_.ptr, type)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Remove ASCII Armor from data.
|
85
|
+
#
|
86
|
+
# @param input [Input] the input to read the ASCII-Armored data from
|
87
|
+
# @param output [Output] the output to write the dearmored data to. If
|
88
|
+
# nil, the result will be returned directly as a String.
|
89
|
+
# @return [nil, String]
|
90
|
+
def self.dearmor(input:, output: nil)
|
91
|
+
Output.default(output) do |output_|
|
92
|
+
Rnp.call_ffi(:rnp_dearmor, input.ptr, output_.ptr)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Get the version of the rnp library as a string.
|
97
|
+
#
|
98
|
+
# @return [String]
|
99
|
+
def self.version_string
|
100
|
+
LibRnp.rnp_version_string
|
101
|
+
end
|
102
|
+
|
103
|
+
# Get the detailed version of the rnp library as a string.
|
104
|
+
#
|
105
|
+
# @return [String]
|
106
|
+
def self.version_string_full
|
107
|
+
LibRnp.rnp_version_string_full
|
108
|
+
end
|
109
|
+
|
110
|
+
# Get the version stamp of the rnp library as an unsigned
|
111
|
+
# 32-bit integer. This number can be compared against other
|
112
|
+
# stamps generated with {version_for}.
|
113
|
+
#
|
114
|
+
# @return [Integer]
|
115
|
+
def self.version
|
116
|
+
LibRnp.rnp_version
|
117
|
+
end
|
118
|
+
|
119
|
+
# Encode the given major, minor, and patch numbers into a version
|
120
|
+
# stamp.
|
121
|
+
#
|
122
|
+
# @return [Integer]
|
123
|
+
def self.version_for(major, minor, patch)
|
124
|
+
LibRnp.rnp_version_for(major, minor, patch)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Extract the major version component from the given version stamp.
|
128
|
+
#
|
129
|
+
# @return [Integer]
|
130
|
+
def self.version_major(version)
|
131
|
+
LibRnp.rnp_version_major(version)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Extract the minor version component from the given version stamp.
|
135
|
+
#
|
136
|
+
# @return [Integer]
|
137
|
+
def self.version_minor(version)
|
138
|
+
LibRnp.rnp_version_minor(version)
|
139
|
+
end
|
140
|
+
|
141
|
+
# Extract the patch version component from the given version stamp.
|
142
|
+
#
|
143
|
+
# @return [Integer]
|
144
|
+
def self.version_patch(version)
|
145
|
+
LibRnp.rnp_version_patch(version)
|
146
|
+
end
|
70
147
|
end # class
|
71
148
|
|
data/lib/rnp/output.rb
CHANGED
@@ -116,6 +116,14 @@ class Rnp
|
|
116
116
|
Rnp.call_ffi(:rnp_output_to_callback, pptr, writercb, nil, nil)
|
117
117
|
Output.new(pptr.read_pointer, writercb)
|
118
118
|
end
|
119
|
+
|
120
|
+
# @api private
|
121
|
+
def self.default(output)
|
122
|
+
to_str = output.nil?
|
123
|
+
output = Output.to_string if to_str
|
124
|
+
yield output
|
125
|
+
output.string if to_str
|
126
|
+
end
|
119
127
|
end # class
|
120
128
|
end # class
|
121
129
|
|
data/lib/rnp/rnp.rb
CHANGED
@@ -252,7 +252,7 @@ class Rnp
|
|
252
252
|
creation_time: nil,
|
253
253
|
expiration_time: nil,
|
254
254
|
hash: nil)
|
255
|
-
|
255
|
+
Output.default(output) do |output_|
|
256
256
|
sign = start_sign(input: input, output: output_)
|
257
257
|
sign.options = {
|
258
258
|
armored: armored,
|
@@ -280,7 +280,7 @@ class Rnp
|
|
280
280
|
creation_time: nil,
|
281
281
|
expiration_time: nil,
|
282
282
|
hash: nil)
|
283
|
-
|
283
|
+
Output.default(output) do |output_|
|
284
284
|
sign = start_cleartext_sign(input: input, output: output_)
|
285
285
|
sign.options = {
|
286
286
|
compression: compression,
|
@@ -309,7 +309,7 @@ class Rnp
|
|
309
309
|
creation_time: nil,
|
310
310
|
expiration_time: nil,
|
311
311
|
hash: nil)
|
312
|
-
|
312
|
+
Output.default(output) do |output_|
|
313
313
|
sign = start_detached_sign(input: input, output: output_)
|
314
314
|
sign.options = {
|
315
315
|
armored: armored,
|
@@ -353,7 +353,7 @@ class Rnp
|
|
353
353
|
armored: nil,
|
354
354
|
compression: nil,
|
355
355
|
cipher: nil)
|
356
|
-
|
356
|
+
Output.default(output) do |output_|
|
357
357
|
enc = start_encrypt(input: input, output: output_)
|
358
358
|
enc.options = {
|
359
359
|
armored: armored,
|
@@ -383,7 +383,7 @@ class Rnp
|
|
383
383
|
hash: nil,
|
384
384
|
creation_time: nil,
|
385
385
|
expiration_time: nil)
|
386
|
-
|
386
|
+
Output.default(output) do |output_|
|
387
387
|
enc = start_encrypt(input: input, output: output_)
|
388
388
|
enc.options = {
|
389
389
|
armored: armored,
|
@@ -417,7 +417,7 @@ class Rnp
|
|
417
417
|
s2k_hash: nil,
|
418
418
|
s2k_iterations: 0,
|
419
419
|
s2k_cipher: nil)
|
420
|
-
|
420
|
+
Output.default(output) do |output_|
|
421
421
|
enc = start_encrypt(input: input, output: output_)
|
422
422
|
enc.options = {
|
423
423
|
armored: armored,
|
@@ -442,7 +442,7 @@ class Rnp
|
|
442
442
|
# If nil, the result will be returned directly as a String.
|
443
443
|
# @return [nil, String]
|
444
444
|
def decrypt(input:, output: nil)
|
445
|
-
|
445
|
+
Output.default(output) do |output_|
|
446
446
|
Rnp.call_ffi(:rnp_decrypt, @ptr, input.ptr, output_.ptr)
|
447
447
|
end
|
448
448
|
end
|
@@ -584,12 +584,5 @@ class Rnp
|
|
584
584
|
flags |= LibRnp::RNP_LOAD_SAVE_SECRET_KEYS if secret_keys
|
585
585
|
flags
|
586
586
|
end
|
587
|
-
|
588
|
-
def default_output(output)
|
589
|
-
to_str = output.nil?
|
590
|
-
output = Output.to_string if to_str
|
591
|
-
yield output
|
592
|
-
output.string if to_str
|
593
|
-
end
|
594
587
|
end # class
|
595
588
|
|
data/lib/rnp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rnp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|