rnp 0.2.0 → 1.0.0

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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +5 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.adoc +3 -182
  5. data/lib/rnp.rb +12 -3
  6. data/lib/rnp/error.rb +40 -0
  7. data/lib/rnp/ffi/librnp.rb +306 -0
  8. data/lib/rnp/input.rb +99 -0
  9. data/lib/rnp/key.rb +275 -0
  10. data/lib/rnp/misc.rb +71 -0
  11. data/lib/rnp/op/encrypt.rb +181 -0
  12. data/lib/rnp/op/sign.rb +139 -0
  13. data/lib/rnp/op/verify.rb +147 -0
  14. data/lib/rnp/output.rb +121 -0
  15. data/lib/rnp/rnp.rb +595 -0
  16. data/lib/rnp/utils.rb +44 -0
  17. data/lib/rnp/version.rb +8 -3
  18. metadata +124 -50
  19. data/.gitignore +0 -12
  20. data/.rspec +0 -2
  21. data/.travis.yml +0 -5
  22. data/CODE_OF_CONDUCT.md +0 -74
  23. data/Gemfile +0 -4
  24. data/Rakefile +0 -6
  25. data/Use_Cases.adoc +0 -119
  26. data/bin/console +0 -14
  27. data/bin/setup +0 -8
  28. data/example-usage.rb +0 -766
  29. data/examples/highlevel/decrypt_mem.rb +0 -44
  30. data/examples/highlevel/encrypt_mem.rb +0 -46
  31. data/examples/lowlevel/decrypt_file.rb +0 -76
  32. data/examples/lowlevel/decrypt_mem.rb +0 -80
  33. data/examples/lowlevel/encrypt_file.rb +0 -68
  34. data/examples/lowlevel/encrypt_mem.rb +0 -75
  35. data/examples/lowlevel/load_pubkey.rb +0 -118
  36. data/examples/lowlevel/print_keyring_file.rb +0 -68
  37. data/examples/lowlevel/print_keyring_mem.rb +0 -96
  38. data/examples/lowlevel/sign_file.rb +0 -104
  39. data/examples/lowlevel/sign_mem.rb +0 -96
  40. data/examples/lowlevel/verify_file.rb +0 -55
  41. data/examples/lowlevel/verify_mem.rb +0 -61
  42. data/lib/rnp/highlevel.rb +0 -5
  43. data/lib/rnp/highlevel/constants.rb +0 -96
  44. data/lib/rnp/highlevel/keyring.rb +0 -259
  45. data/lib/rnp/highlevel/publickey.rb +0 -150
  46. data/lib/rnp/highlevel/secretkey.rb +0 -318
  47. data/lib/rnp/highlevel/utils.rb +0 -119
  48. data/lib/rnp/lowlevel.rb +0 -6
  49. data/lib/rnp/lowlevel/constants.rb +0 -11
  50. data/lib/rnp/lowlevel/dynarray.rb +0 -129
  51. data/lib/rnp/lowlevel/enums.rb +0 -243
  52. data/lib/rnp/lowlevel/libc.rb +0 -28
  53. data/lib/rnp/lowlevel/libopenssl.rb +0 -15
  54. data/lib/rnp/lowlevel/librnp.rb +0 -213
  55. data/lib/rnp/lowlevel/structs.rb +0 -541
  56. data/lib/rnp/lowlevel/utils.rb +0 -25
  57. data/rnp.gemspec +0 -35
  58. data/rnp/lib/rnp.rb +0 -5
  59. data/rnp/spec/rnp_spec.rb +0 -11
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (c) 2018 Ribose Inc.
4
+
5
+ require 'ffi'
6
+
7
+ require 'rnp/error'
8
+ require 'rnp/ffi/librnp'
9
+
10
+ class Rnp
11
+ # @api private
12
+ #
13
+ # Calls the LibRnp FFI function indicated.
14
+ # If the return code is <0, an error will be raised.
15
+ #
16
+ # @param fn [Symbol] the name of the function to call
17
+ # @param args the arguments to pass to the FFI function
18
+ # @return [void]
19
+ def self.call_ffi(fn, *args)
20
+ rc = LibRnp.method(fn).call(*args)
21
+ Rnp.raise_error("#{fn} failed", rc) unless rc.zero?
22
+ nil
23
+ end
24
+
25
+ # @api private
26
+ def self.inspect_ptr(myself)
27
+ ptr_format = "0x%0#{FFI::Pointer.size * 2}x"
28
+ ptr_s = format(ptr_format, myself.instance_variable_get(:@ptr).address)
29
+ class_name = myself.class.to_s
30
+ "#<#{class_name}:#{ptr_s}>"
31
+ end
32
+
33
+ unless FFI::MemoryPointer.respond_to?(:from_data)
34
+ # @api private
35
+ class << FFI::MemoryPointer
36
+ def from_data(data)
37
+ buf = FFI::MemoryPointer.new(:uint8, data.bytesize)
38
+ buf.write_bytes(data)
39
+ buf
40
+ end
41
+ end
42
+ end
43
+ end # class
44
+
@@ -1,3 +1,8 @@
1
- module Rnp
2
- VERSION = "0.2.0"
3
- end
1
+ # frozen_string_literal: true
2
+
3
+ # (c) 2018 Ribose Inc.
4
+
5
+ class Rnp
6
+ VERSION = '1.0.0'
7
+ end # class
8
+
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rnp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-25 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: asciidoctor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rake
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +66,20 @@ dependencies:
38
66
  - - "~>"
39
67
  - !ruby/object:Gem::Version
40
68
  version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: redcarpet
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: rspec
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -52,61 +94,93 @@ dependencies:
52
94
  - - "~>"
53
95
  - !ruby/object:Gem::Version
54
96
  version: '3.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.55.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.55.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.14'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.14'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.9.12
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.9.12
139
+ - !ruby/object:Gem::Dependency
140
+ name: ffi
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.9'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.9'
55
153
  description: Support rnp's OpenPGP functionality via ruby-ffi. Requires librnp.so.
56
154
  email:
57
155
  - open.source@ribose.com
58
156
  executables: []
59
157
  extensions: []
60
- extra_rdoc_files: []
158
+ extra_rdoc_files:
159
+ - README.adoc
160
+ - CHANGELOG.adoc
161
+ - LICENSE.txt
61
162
  files:
62
- - ".gitignore"
63
- - ".rspec"
64
- - ".travis.yml"
65
- - CODE_OF_CONDUCT.md
66
- - Gemfile
67
- - Gemfile.lock
163
+ - CHANGELOG.adoc
164
+ - LICENSE.txt
68
165
  - README.adoc
69
- - Rakefile
70
- - Use_Cases.adoc
71
- - bin/console
72
- - bin/setup
73
- - example-usage.rb
74
- - examples/highlevel/decrypt_mem.rb
75
- - examples/highlevel/encrypt_mem.rb
76
- - examples/lowlevel/decrypt_file.rb
77
- - examples/lowlevel/decrypt_mem.rb
78
- - examples/lowlevel/encrypt_file.rb
79
- - examples/lowlevel/encrypt_mem.rb
80
- - examples/lowlevel/load_pubkey.rb
81
- - examples/lowlevel/print_keyring_file.rb
82
- - examples/lowlevel/print_keyring_mem.rb
83
- - examples/lowlevel/sign_file.rb
84
- - examples/lowlevel/sign_mem.rb
85
- - examples/lowlevel/verify_file.rb
86
- - examples/lowlevel/verify_mem.rb
87
166
  - lib/rnp.rb
88
- - lib/rnp/highlevel.rb
89
- - lib/rnp/highlevel/constants.rb
90
- - lib/rnp/highlevel/keyring.rb
91
- - lib/rnp/highlevel/publickey.rb
92
- - lib/rnp/highlevel/secretkey.rb
93
- - lib/rnp/highlevel/utils.rb
94
- - lib/rnp/lowlevel.rb
95
- - lib/rnp/lowlevel/constants.rb
96
- - lib/rnp/lowlevel/dynarray.rb
97
- - lib/rnp/lowlevel/enums.rb
98
- - lib/rnp/lowlevel/libc.rb
99
- - lib/rnp/lowlevel/libopenssl.rb
100
- - lib/rnp/lowlevel/librnp.rb
101
- - lib/rnp/lowlevel/structs.rb
102
- - lib/rnp/lowlevel/utils.rb
167
+ - lib/rnp/error.rb
168
+ - lib/rnp/ffi/librnp.rb
169
+ - lib/rnp/input.rb
170
+ - lib/rnp/key.rb
171
+ - lib/rnp/misc.rb
172
+ - lib/rnp/op/encrypt.rb
173
+ - lib/rnp/op/sign.rb
174
+ - lib/rnp/op/verify.rb
175
+ - lib/rnp/output.rb
176
+ - lib/rnp/rnp.rb
177
+ - lib/rnp/utils.rb
103
178
  - lib/rnp/version.rb
104
- - rnp.gemspec
105
- - rnp/lib/rnp.rb
106
- - rnp/spec/rnp_spec.rb
107
179
  homepage: https://www.ribose.com
108
- licenses: []
109
- metadata: {}
180
+ licenses:
181
+ - MIT
182
+ metadata:
183
+ yard.run: yard
110
184
  post_install_message:
111
185
  rdoc_options: []
112
186
  require_paths:
@@ -115,7 +189,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
189
  requirements:
116
190
  - - ">="
117
191
  - !ruby/object:Gem::Version
118
- version: '0'
192
+ version: 2.3.0
119
193
  required_rubygems_version: !ruby/object:Gem::Requirement
120
194
  requirements:
121
195
  - - ">="
@@ -123,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
197
  version: '0'
124
198
  requirements: []
125
199
  rubyforge_project:
126
- rubygems_version: 2.5.2
200
+ rubygems_version: 2.6.14
127
201
  signing_key:
128
202
  specification_version: 4
129
203
  summary: Ruby bindings for the rnp OpenPGP library
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
-
11
- # rspec failure tracking
12
- .rspec_status
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.3
5
- before_install: gem install bundler -v 1.14.6
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at ronald.tse@ribose.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in rnp.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,119 +0,0 @@
1
- = Use Cases
2
-
3
- 1. Generate or import a secret key, and read its properties:
4
-
5
- [source,ruby]
6
- ----
7
- key = Rnp::SecretKey.new
8
- key.generate(
9
- key_length: Integer,
10
- public_key_algorithm: PublicKeyAlgorithm::RSA,
11
- algorithm_params: { e: Integer }, # content is public_key_algorithm specific
12
- userid: String || Userid,
13
- hash_algorithm: HashAlgorithm,
14
- symmetric_key_algorithm: SymmetricKeyAlgorithm
15
- )
16
-
17
- key.version # must be 4
18
- key.userids # => [] with its User ID packets
19
- key.userid_signatures # => [] of Signature Packets of its User ID packets
20
- key.passphrase # sets the passphrase if non-blank
21
- key.key_id # => key id of key
22
- key.fingerprint # => fingerprint of key
23
- key.key_length # length of key
24
- ----
25
-
26
-
27
- 2. (Generate and) Add a Subkey to a secret key:
28
-
29
- [source,ruby]
30
- ----
31
- subkey = SecretSubkeyPacketV4.new
32
- subkey.generate(
33
- key_length: Integer,
34
- public_key_algorithm: PublicKeyAlgorithm,
35
- algorithm_params: { e: Integer }, # content is public_key_algorithm specific
36
- userid: String || Userid,
37
- hash_algorithm: HashAlgorithm,
38
- symmetric_key_algorithm: SymmetricKeyAlgorithm
39
- )
40
-
41
- # Adds subkey to key
42
- key.add_subkey(subkey)
43
-
44
- # Or
45
- subkey_self_sig = Signature.new
46
- subkey_self_sig.type = SignatureType::SubkeyBinding
47
- subkey_self_sig.userid = userid
48
- subkey_self_sig.key_flags = [:encrypt_data, :encrypt_comm, :cert]
49
- subkey_self_sig.key_expiration_time = DateTime
50
- subkey_self_sig.creation_time = DateTime
51
-
52
- ----
53
-
54
- 3. Sign and verify a PGP message
55
-
56
- [source,ruby]
57
- ----
58
- # Plaintext OpenPGP message
59
- plaintext_data = File.read("plaintext.txt")
60
- # automatically creates a LiteralDataPacket inside
61
- literal_message = LiteralMessage.new(plaintext_data)
62
-
63
- # Signed OpenPGP message
64
- message = SignedMessage.new(literal_message)
65
- message.content = literal_message # alternative to above
66
- message.key = SecretKey
67
- message.sign # => SignedMessage [SignaturePacket, LiteralMessage]
68
-
69
- # Or
70
- message = OnePassSignedMessage.new(
71
- signature_type: PositiveCertification,
72
- hash_algorithm: HashAlgorithm,
73
- public_key_algorithm: PublicKeyAlgorithm,
74
- key: SecretKey || PublicKey,
75
- content: literal_message
76
- ) # => OnePassSignedMessage is an OpenPgpMessage
77
-
78
- message.to_s # ASCII armored message
79
-
80
- # Verifying a PGP message
81
- public_key.verify(message.signature, message.content)
82
- secret_key.verify(message.signature, message.content)
83
- ----
84
-
85
- 4. Encrypt and decrypt a PGP message
86
-
87
- [source,ruby]
88
- ----
89
- # Encrypted OpenPGP message
90
- message = EncryptedMessage.new
91
- message.key = YourPublicKey
92
- message.public_key_algorithm = PublicKeyAlgorithm
93
- message.content = plaintext_data
94
-
95
- # Decrypt OpenPGP message
96
- message = Rnp::OpenPgpMessage.new
97
-
98
- # Importing from ASCII armored PGP message
99
- message.import_ascii(File.read("ascii_armored_pgp_message.txt"))
100
-
101
- # Importing unarmored content
102
- message.import_raw(File.read("base64_portion_of_multipart_email.eml"))
103
-
104
- message.signature # => signature of message in Rnp::Signature
105
- message.signer_userid # => signer in Rnp::Userid
106
- message.signed? # => is message signed?
107
- message.encrypted? # => is message encrypted?
108
- message.decrypt(key) # => decrypt content of message
109
- message.content # => decrypted content of message
110
- ----
111
-
112
- 5. Packet and Keychain functionalities.
113
-
114
- While these are not crucial, the Packet stuff will aid a higher level
115
- implementation.
116
-
117
- The `rnp_*` functions do support signing / verifying / encrypting /
118
- decrypting, but for generate key (Case 1) especially for subkeys we need
119
- to implement the remaining stuff in Ruby.