rnp 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +26 -0
- data/README.adoc +208 -0
- data/Rakefile +6 -0
- data/Use_Cases.adoc +119 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/example-usage.rb +766 -0
- data/examples/highlevel/decrypt_mem.rb +44 -0
- data/examples/highlevel/encrypt_mem.rb +46 -0
- data/examples/lowlevel/decrypt_file.rb +76 -0
- data/examples/lowlevel/decrypt_mem.rb +80 -0
- data/examples/lowlevel/encrypt_file.rb +68 -0
- data/examples/lowlevel/encrypt_mem.rb +75 -0
- data/examples/lowlevel/load_pubkey.rb +118 -0
- data/examples/lowlevel/print_keyring_file.rb +68 -0
- data/examples/lowlevel/print_keyring_mem.rb +96 -0
- data/examples/lowlevel/sign_file.rb +104 -0
- data/examples/lowlevel/sign_mem.rb +96 -0
- data/examples/lowlevel/verify_file.rb +55 -0
- data/examples/lowlevel/verify_mem.rb +61 -0
- data/lib/rnp/highlevel/constants.rb +96 -0
- data/lib/rnp/highlevel/keyring.rb +259 -0
- data/lib/rnp/highlevel/publickey.rb +150 -0
- data/lib/rnp/highlevel/secretkey.rb +318 -0
- data/lib/rnp/highlevel/utils.rb +119 -0
- data/lib/rnp/highlevel.rb +5 -0
- data/lib/rnp/lowlevel/constants.rb +11 -0
- data/lib/rnp/lowlevel/dynarray.rb +129 -0
- data/lib/rnp/lowlevel/enums.rb +243 -0
- data/lib/rnp/lowlevel/libc.rb +28 -0
- data/lib/rnp/lowlevel/libopenssl.rb +15 -0
- data/lib/rnp/lowlevel/librnp.rb +213 -0
- data/lib/rnp/lowlevel/structs.rb +541 -0
- data/lib/rnp/lowlevel/utils.rb +25 -0
- data/lib/rnp/lowlevel.rb +6 -0
- data/lib/rnp/version.rb +3 -0
- data/lib/rnp.rb +5 -0
- data/rnp/lib/rnp.rb +5 -0
- data/rnp/spec/rnp_spec.rb +11 -0
- data/rnp.gemspec +35 -0
- metadata +82 -9
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module LibRNP
|
4
|
+
|
5
|
+
def self.dynarray_count(struct, field)
|
6
|
+
struct[(field + 'c').to_sym]
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.dynarray_vsize(struct, field)
|
10
|
+
struct[(field + 'vsize').to_sym]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.dynarray_items(struct, field)
|
14
|
+
struct[(field + 's').to_sym]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.dynarray_get_item(struct, field, type, index)
|
18
|
+
count = dynarray_count(struct, field)
|
19
|
+
if index >= count
|
20
|
+
return nil
|
21
|
+
end
|
22
|
+
|
23
|
+
items = dynarray_items(struct, field)
|
24
|
+
case type
|
25
|
+
when :pointer
|
26
|
+
ptrs = items.read_array_of_pointer(count)
|
27
|
+
ptrs[index]
|
28
|
+
when :string
|
29
|
+
ptrs = items.read_array_of_pointer(count)
|
30
|
+
ptrs[index].read_string
|
31
|
+
else
|
32
|
+
ptrs = FFI::Pointer.new(type, items)
|
33
|
+
type.new(ptrs[index])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Appends an item to a DYNARRAY, expanding the array as needed.
|
38
|
+
#
|
39
|
+
# @param struct [FFI::Struct] Structure where the DYNARRAY is held.
|
40
|
+
# @param field [String] The name of the DYNARRAY within the structure.
|
41
|
+
# For example, this would be 'uid' if the array were declared natively
|
42
|
+
# with something like DYNARRAY(uint8_t*, uid);
|
43
|
+
# @param type [FFI::Struct, :pointer, :string] The type (class) of the
|
44
|
+
# elements in the DYNARRAY, or the special values :pointer or :string.
|
45
|
+
# @param value [FFI::Struct, FFI::Pointer, String] The value to append. When
|
46
|
+
# type is an FFI::Struct class, the bytes will be copied from the struct,
|
47
|
+
# directly to the DYNARRAY memory.
|
48
|
+
# When type is :pointer, the pointer (not data) is copied to the DYNARRAY.
|
49
|
+
# When type is :string, the string data will be allocated and a pointer will
|
50
|
+
# be copied in to the DYNARRAY.
|
51
|
+
def self.dynarray_append_item(struct, field, type, value)
|
52
|
+
dynarray_expand(struct, field, type)
|
53
|
+
|
54
|
+
count = dynarray_count(struct, field)
|
55
|
+
items = dynarray_items(struct, field)
|
56
|
+
case type
|
57
|
+
when :pointer
|
58
|
+
ptrs = items.read_array_of_pointer(count + 1)
|
59
|
+
ptrs[count] = value
|
60
|
+
items.write_array_of_pointer(ptrs)
|
61
|
+
when :string
|
62
|
+
ptrs = items.read_array_of_pointer(count + 1)
|
63
|
+
mem = LibC::calloc(1, value.size + 1)
|
64
|
+
mem.write_bytes(value)
|
65
|
+
ptrs[count] = mem
|
66
|
+
items.write_array_of_pointer(ptrs)
|
67
|
+
else
|
68
|
+
ptrs = FFI::Pointer.new(type, items)
|
69
|
+
bytes = value.pointer.read_bytes(type.size)
|
70
|
+
ptrs[count].write_bytes(bytes)
|
71
|
+
end
|
72
|
+
struct[(field + 'c').to_sym] = count + 1
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.dynarray_expand(struct, field, type)
|
76
|
+
count = dynarray_count(struct, field)
|
77
|
+
vsize = dynarray_vsize(struct, field)
|
78
|
+
# return if expansion is not necessary
|
79
|
+
return if count != vsize
|
80
|
+
|
81
|
+
newvsize = (vsize * 2) + 10
|
82
|
+
mem = dynarray_items(struct, field)
|
83
|
+
case type
|
84
|
+
when :pointer, :string
|
85
|
+
itemsize = FFI::Pointer.size
|
86
|
+
else
|
87
|
+
itemsize = type.size
|
88
|
+
end
|
89
|
+
newarr = LibC::realloc(mem, newvsize * itemsize)
|
90
|
+
LibC::memset(newarr + (vsize * itemsize), 0, (newvsize - vsize) * itemsize)
|
91
|
+
struct[(field + 'vsize').to_sym] = newvsize
|
92
|
+
struct[(field + 's').to_sym] = newarr
|
93
|
+
end
|
94
|
+
|
95
|
+
# Clear a dynarray so that the item count is zero.
|
96
|
+
#
|
97
|
+
# @param struct [FFI::Struct] Structure where the DYNARRAY is held.
|
98
|
+
# @param field [String] The name of the DYNARRAY within the structure.
|
99
|
+
# For example, this would be 'uid' if the array were declared natively
|
100
|
+
# with something like DYNARRAY(uint8_t*, uid);
|
101
|
+
# @param type [FFI::Struct, :pointer, :string] The type (class) of the
|
102
|
+
# elements in the DYNARRAY, or the special values :pointer or :string.
|
103
|
+
#
|
104
|
+
# When type is :pointer or :string, LibC::free will be called on
|
105
|
+
# the pointers first.
|
106
|
+
#
|
107
|
+
# The memory will also be zeroed out.
|
108
|
+
def self.dynarray_clear(struct, field, type)
|
109
|
+
count = dynarray_count(struct, field)
|
110
|
+
mem = dynarray_items(struct, field)
|
111
|
+
return if count == 0 or mem.null?
|
112
|
+
|
113
|
+
vsize = dynarray_vsize(struct, field)
|
114
|
+
case type
|
115
|
+
when :pointer, :string
|
116
|
+
itemsize = FFI::Pointer.size
|
117
|
+
ptrs = FFI::Pointer.new(:pointer, mem)
|
118
|
+
(0..count-1).each {|n|
|
119
|
+
LibC::free(ptrs[n].read_pointer())
|
120
|
+
}
|
121
|
+
else
|
122
|
+
itemsize = type.size
|
123
|
+
end
|
124
|
+
LibC::memset(mem, 0, vsize * itemsize)
|
125
|
+
struct[(field + 'c').to_sym] = 0
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
@@ -0,0 +1,243 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module LibRNP
|
4
|
+
extend FFI::Library
|
5
|
+
|
6
|
+
enum :pgp_s2k_usage_t, [
|
7
|
+
:PGP_S2KU_NONE, 0,
|
8
|
+
:PGP_S2KU_ENCRYPTED_AND_HASHED, 254,
|
9
|
+
:PGP_S2KU_ENCRYPTED, 255
|
10
|
+
]
|
11
|
+
enum :pgp_s2k_specifier_t, [
|
12
|
+
:PGP_S2KS_SIMPLE, 0,
|
13
|
+
:PGP_S2KS_SALTED, 1,
|
14
|
+
:PGP_S2KS_ITERATED_AND_SALTED, 3
|
15
|
+
]
|
16
|
+
enum :pgp_compression_type_t, [
|
17
|
+
:PGP_C_NONE, 0,
|
18
|
+
:PGP_C_ZIP, 1,
|
19
|
+
:PGP_C_ZLIB, 2,
|
20
|
+
:PGP_C_BZIP2, 3
|
21
|
+
]
|
22
|
+
enum :pgp_symm_alg_t, [
|
23
|
+
:PGP_SA_PLAINTEXT, 0,
|
24
|
+
:PGP_SA_IDEA, 1,
|
25
|
+
:PGP_SA_TRIPLEDES, 2,
|
26
|
+
:PGP_SA_CAST5, 3,
|
27
|
+
:PGP_SA_BLOWFISH, 4,
|
28
|
+
:PGP_SA_AES_128, 7,
|
29
|
+
:PGP_SA_AES_192, 8,
|
30
|
+
:PGP_SA_AES_256, 9,
|
31
|
+
:PGP_SA_TWOFISH, 10,
|
32
|
+
:PGP_SA_CAMELLIA_128, 100,
|
33
|
+
:PGP_SA_CAMELLIA_192, 101,
|
34
|
+
:PGP_SA_CAMELLIA_256, 102
|
35
|
+
]
|
36
|
+
enum :pgp_cb_ret_t, [
|
37
|
+
:PGP_RELEASE_MEMORY,
|
38
|
+
:PGP_KEEP_MEMORY,
|
39
|
+
:PGP_FINISHED
|
40
|
+
]
|
41
|
+
enum :pgp_content_enum, [
|
42
|
+
:PGP_PTAG_CT_RESERVE, 0,
|
43
|
+
:PGP_PTAG_CT_PK_SESSION_KEY, 1,
|
44
|
+
:PGP_PTAG_CT_SIGNATURE, 2,
|
45
|
+
:PGP_PTAG_CT_SK_SESSION_KEY, 3,
|
46
|
+
:PGP_PTAG_CT_1_PASS_SIG, 4,
|
47
|
+
:PGP_PTAG_CT_SECRET_KEY, 5,
|
48
|
+
:PGP_PTAG_CT_PUBLIC_KEY, 6,
|
49
|
+
:PGP_PTAG_CT_SECRET_SUBKEY, 7,
|
50
|
+
:PGP_PTAG_CT_COMPRESSED, 8,
|
51
|
+
:PGP_PTAG_CT_SE_DATA, 9,
|
52
|
+
:PGP_PTAG_CT_MARKER, 10,
|
53
|
+
:PGP_PTAG_CT_LITDATA, 11,
|
54
|
+
:PGP_PTAG_CT_TRUST, 12,
|
55
|
+
:PGP_PTAG_CT_USER_ID, 13,
|
56
|
+
:PGP_PTAG_CT_PUBLIC_SUBKEY, 14,
|
57
|
+
:PGP_PTAG_CT_RESERVED2, 15,
|
58
|
+
:PGP_PTAG_CT_RESERVED3, 16,
|
59
|
+
:PGP_PTAG_CT_USER_ATTR, 17,
|
60
|
+
:PGP_PTAG_CT_SE_IP_DATA, 18,
|
61
|
+
:PGP_PTAG_CT_MDC, 19,
|
62
|
+
:PGP_PARSER_PTAG, 0x100,
|
63
|
+
:PGP_PTAG_RAW_SS, 0x101,
|
64
|
+
:PGP_PTAG_SS_ALL, 0x102,
|
65
|
+
:PGP_PARSER_PACKET_END, 0x103,
|
66
|
+
:PGP_PTAG_SIG_SUBPKT_BASE, 0x200,
|
67
|
+
:PGP_PTAG_SS_CREATION_TIME, 0x200 + 2,
|
68
|
+
:PGP_PTAG_SS_EXPIRATION_TIME, 0x200 + 3,
|
69
|
+
:PGP_PTAG_SS_EXPORT_CERT, 0x200 + 4,
|
70
|
+
:PGP_PTAG_SS_TRUST, 0x200 + 5,
|
71
|
+
:PGP_PTAG_SS_REGEXP, 0x200 + 6,
|
72
|
+
:PGP_PTAG_SS_REVOCABLE, 0x200 + 7,
|
73
|
+
:PGP_PTAG_SS_KEY_EXPIRY, 0x200 + 9,
|
74
|
+
:PGP_PTAG_SS_RESERVED, 0x200 + 10,
|
75
|
+
:PGP_PTAG_SS_PREFERRED_SKA, 0x200 + 11,
|
76
|
+
:PGP_PTAG_SS_REVOCATION_KEY, 0x200 + 12,
|
77
|
+
:PGP_PTAG_SS_ISSUER_KEY_ID, 0x200 + 16,
|
78
|
+
:PGP_PTAG_SS_NOTATION_DATA, 0x200 + 20,
|
79
|
+
:PGP_PTAG_SS_PREFERRED_HASH, 0x200 + 21,
|
80
|
+
:PGP_PTAG_SS_PREF_COMPRESS, 0x200 + 22,
|
81
|
+
:PGP_PTAG_SS_KEYSERV_PREFS, 0x200 + 23,
|
82
|
+
:PGP_PTAG_SS_PREF_KEYSERV, 0x200 + 24,
|
83
|
+
:PGP_PTAG_SS_PRIMARY_USER_ID, 0x200 + 25,
|
84
|
+
:PGP_PTAG_SS_POLICY_URI, 0x200 + 26,
|
85
|
+
:PGP_PTAG_SS_KEY_FLAGS, 0x200 + 27,
|
86
|
+
:PGP_PTAG_SS_SIGNERS_USER_ID, 0x200 + 28,
|
87
|
+
:PGP_PTAG_SS_REVOCATION_REASON, 0x200 + 29,
|
88
|
+
:PGP_PTAG_SS_FEATURES, 0x200 + 30,
|
89
|
+
:PGP_PTAG_SS_SIGNATURE_TARGET, 0x200 + 31,
|
90
|
+
:PGP_PTAG_SS_EMBEDDED_SIGNATURE, 0x200 + 32,
|
91
|
+
:PGP_PTAG_SS_USERDEFINED00, 0x200 + 100,
|
92
|
+
:PGP_PTAG_SS_USERDEFINED01, 0x200 + 101,
|
93
|
+
:PGP_PTAG_SS_USERDEFINED02, 0x200 + 102,
|
94
|
+
:PGP_PTAG_SS_USERDEFINED03, 0x200 + 103,
|
95
|
+
:PGP_PTAG_SS_USERDEFINED04, 0x200 + 104,
|
96
|
+
:PGP_PTAG_SS_USERDEFINED05, 0x200 + 105,
|
97
|
+
:PGP_PTAG_SS_USERDEFINED06, 0x200 + 106,
|
98
|
+
:PGP_PTAG_SS_USERDEFINED07, 0x200 + 107,
|
99
|
+
:PGP_PTAG_SS_USERDEFINED08, 0x200 + 108,
|
100
|
+
:PGP_PTAG_SS_USERDEFINED09, 0x200 + 109,
|
101
|
+
:PGP_PTAG_SS_USERDEFINED10, 0x200 + 110,
|
102
|
+
:PGP_PTAG_CT_LITDATA_HEADER, 0x300,
|
103
|
+
:PGP_PTAG_CT_LITDATA_BODY, 0x300 + 1,
|
104
|
+
:PGP_PTAG_CT_SIGNATURE_HEADER, 0x300 + 2,
|
105
|
+
:PGP_PTAG_CT_SIGNATURE_FOOTER, 0x300 + 3,
|
106
|
+
:PGP_PTAG_CT_ARMOUR_HEADER, 0x300 + 4,
|
107
|
+
:PGP_PTAG_CT_ARMOUR_TRAILER, 0x300 + 5,
|
108
|
+
:PGP_PTAG_CT_SIGNED_CLEARTEXT_HEADER, 0x300 + 6,
|
109
|
+
:PGP_PTAG_CT_SIGNED_CLEARTEXT_BODY, 0x300 + 7,
|
110
|
+
:PGP_PTAG_CT_SIGNED_CLEARTEXT_TRAILER, 0x300 + 8,
|
111
|
+
:PGP_PTAG_CT_UNARMOURED_TEXT, 0x300 + 9,
|
112
|
+
:PGP_PTAG_CT_ENCRYPTED_SECRET_KEY, 0x300 + 10,
|
113
|
+
:PGP_PTAG_CT_ENCRYPTED_SECRET_SUBKEY, 0x300 + 11,
|
114
|
+
:PGP_PTAG_CT_SE_DATA_HEADER, 0x300 + 12,
|
115
|
+
:PGP_PTAG_CT_SE_DATA_BODY, 0x300 + 13,
|
116
|
+
:PGP_PTAG_CT_SE_IP_DATA_HEADER, 0x300 + 14,
|
117
|
+
:PGP_PTAG_CT_SE_IP_DATA_BODY, 0x300 + 15,
|
118
|
+
:PGP_PTAG_CT_ENCRYPTED_PK_SESSION_KEY, 0x300 + 16,
|
119
|
+
:PGP_GET_PASSPHRASE, 0x400,
|
120
|
+
:PGP_GET_SECKEY, 0x400 + 1,
|
121
|
+
:PGP_PARSER_ERROR, 0x500,
|
122
|
+
:PGP_PARSER_ERRCODE, 0x500 + 1,
|
123
|
+
]
|
124
|
+
enum :pgp_parse_type_t, [
|
125
|
+
:PGP_PARSE_RAW,
|
126
|
+
:PGP_PARSE_PARSED,
|
127
|
+
:PGP_PARSE_IGNORE
|
128
|
+
]
|
129
|
+
enum :pgp_errcode_t, [
|
130
|
+
:PGP_E_OK, 0x0000,
|
131
|
+
:PGP_E_FAIL, 0x0001,
|
132
|
+
:PGP_E_SYSTEM_ERROR, 0x0002,
|
133
|
+
:PGP_E_UNIMPLEMENTED, 0x0003,
|
134
|
+
:PGP_E_R, 0x1000,
|
135
|
+
:PGP_E_R_READ_FAILED, 0x1000 + 1,
|
136
|
+
:PGP_E_R_EARLY_EOF, 0x1000 + 2,
|
137
|
+
:PGP_E_R_BAD_FORMAT, 0x1000 + 3,
|
138
|
+
:PGP_E_R_UNSUPPORTED, 0x1000 + 4,
|
139
|
+
:PGP_E_R_UNCONSUMED_DATA, 0x1000 + 5,
|
140
|
+
:PGP_E_W, 0x2000,
|
141
|
+
:PGP_E_W_WRITE_FAILED, 0x2000 + 1,
|
142
|
+
:PGP_E_W_WRITE_TOO_SHORT, 0x2000 + 2,
|
143
|
+
:PGP_E_P, 0x3000,
|
144
|
+
:PGP_E_P_NOT_ENOUGH_DATA, 0x3000 + 1,
|
145
|
+
:PGP_E_P_UNKNOWN_TAG, 0x3000 + 2,
|
146
|
+
:PGP_E_P_PACKET_CONSUMED, 0x3000 + 3,
|
147
|
+
:PGP_E_P_MPI_FORMAT_ERROR, 0x3000 + 4,
|
148
|
+
:PGP_E_P_PACKET_NOT_CONSUMED, 0x3000 + 5,
|
149
|
+
:PGP_E_P_DECOMPRESSION_ERROR, 0x3000 + 6,
|
150
|
+
:PGP_E_P_NO_USERID, 0x3000 + 7,
|
151
|
+
:PGP_E_C, 0x4000,
|
152
|
+
:PGP_E_V, 0x5000,
|
153
|
+
:PGP_E_V_BAD_SIGNATURE, 0x5000 + 1,
|
154
|
+
:PGP_E_V_NO_SIGNATURE, 0x5000 + 2,
|
155
|
+
:PGP_E_V_UNKNOWN_SIGNER, 0x5000 + 3,
|
156
|
+
:PGP_E_V_BAD_HASH, 0x5000 + 4,
|
157
|
+
:PGP_E_ALG, 0x6000,
|
158
|
+
:PGP_E_ALG_UNSUPPORTED_SYMMETRIC_ALG, 0x6000 + 1,
|
159
|
+
:PGP_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG, 0x6000 + 2,
|
160
|
+
:PGP_E_ALG_UNSUPPORTED_SIGNATURE_ALG, 0x6000 + 3,
|
161
|
+
:PGP_E_ALG_UNSUPPORTED_HASH_ALG, 0x6000 + 4,
|
162
|
+
:PGP_E_ALG_UNSUPPORTED_COMPRESS_ALG, 0x6000 + 5,
|
163
|
+
:PGP_E_PROTO, 0x7000,
|
164
|
+
:PGP_E_PROTO_BAD_SYMMETRIC_DECRYPT, 0x7000 + 2,
|
165
|
+
:PGP_E_PROTO_UNKNOWN_SS, 0x7000 + 3,
|
166
|
+
:PGP_E_PROTO_CRITICAL_SS_IGNORED, 0x7000 + 4,
|
167
|
+
:PGP_E_PROTO_BAD_PUBLIC_KEY_VRSN, 0x7000 + 5,
|
168
|
+
:PGP_E_PROTO_BAD_SIGNATURE_VRSN, 0x7000 + 6,
|
169
|
+
:PGP_E_PROTO_BAD_ONE_PASS_SIG_VRSN, 0x7000 + 7,
|
170
|
+
:PGP_E_PROTO_BAD_PKSK_VRSN, 0x7000 + 8,
|
171
|
+
:PGP_E_PROTO_DECRYPTED_MSG_WRONG_LEN, 0x7000 + 9,
|
172
|
+
:PGP_E_PROTO_BAD_SK_CHECKSUM, 0x7000 + 10
|
173
|
+
]
|
174
|
+
enum :pgp_ptag_of_lt_t, [
|
175
|
+
:PGP_PTAG_OLD_LEN_1, 0x00,
|
176
|
+
:PGP_PTAG_OLD_LEN_2, 0x01,
|
177
|
+
:PGP_PTAG_OLD_LEN_4, 0x02,
|
178
|
+
:PGP_PTAG_OLD_LEN_INDETERMINATE, 0x03
|
179
|
+
]
|
180
|
+
enum :pgp_version_t, [
|
181
|
+
:PGP_V2, 2,
|
182
|
+
:PGP_V3, 3,
|
183
|
+
:PGP_V4, 4
|
184
|
+
]
|
185
|
+
PGP_PUBKEY_ALG_T = enum :pgp_pubkey_alg_t, [
|
186
|
+
:PGP_PKA_NOTHING, 0,
|
187
|
+
:PGP_PKA_RSA, 1,
|
188
|
+
:PGP_PKA_RSA_ENCRYPT_ONLY, 2,
|
189
|
+
:PGP_PKA_RSA_SIGN_ONLY, 3,
|
190
|
+
:PGP_PKA_ELGAMAL, 16,
|
191
|
+
:PGP_PKA_DSA, 17,
|
192
|
+
:PGP_PKA_RESERVED_ELLIPTIC_CURVE, 18,
|
193
|
+
:PGP_PKA_RESERVED_ECDSA, 19,
|
194
|
+
:PGP_PKA_ELGAMAL_ENCRYPT_OR_SIGN, 20,
|
195
|
+
:PGP_PKA_RESERVED_DH, 21,
|
196
|
+
:PGP_PKA_PRIVATE00, 100,
|
197
|
+
:PGP_PKA_PRIVATE01, 101,
|
198
|
+
:PGP_PKA_PRIVATE02, 102,
|
199
|
+
:PGP_PKA_PRIVATE03, 103,
|
200
|
+
:PGP_PKA_PRIVATE04, 104,
|
201
|
+
:PGP_PKA_PRIVATE05, 105,
|
202
|
+
:PGP_PKA_PRIVATE06, 106,
|
203
|
+
:PGP_PKA_PRIVATE07, 107,
|
204
|
+
:PGP_PKA_PRIVATE08, 108,
|
205
|
+
:PGP_PKA_PRIVATE09, 109,
|
206
|
+
:PGP_PKA_PRIVATE10, 110,
|
207
|
+
]
|
208
|
+
enum :pgp_hash_alg_t, [
|
209
|
+
:PGP_HASH_UNKNOWN, -1,
|
210
|
+
:PGP_HASH_MD5, 1,
|
211
|
+
:PGP_HASH_SHA1, 2,
|
212
|
+
:PGP_HASH_RIPEMD, 3,
|
213
|
+
:PGP_HASH_SHA256, 8,
|
214
|
+
:PGP_HASH_SHA384, 9,
|
215
|
+
:PGP_HASH_SHA512, 10,
|
216
|
+
:PGP_HASH_SHA224, 11
|
217
|
+
]
|
218
|
+
enum :pgp_sig_type_t, [
|
219
|
+
:PGP_SIG_BINARY, 0x00,
|
220
|
+
:PGP_SIG_TEXT, 0x01,
|
221
|
+
:PGP_SIG_STANDALONE, 0x02,
|
222
|
+
:PGP_CERT_GENERIC, 0x10,
|
223
|
+
:PGP_CERT_PERSONA, 0x11,
|
224
|
+
:PGP_CERT_CASUAL, 0x12,
|
225
|
+
:PGP_CERT_POSITIVE, 0x13,
|
226
|
+
:PGP_SIG_SUBKEY, 0x18,
|
227
|
+
:PGP_SIG_PRIMARY, 0x19,
|
228
|
+
:PGP_SIG_DIRECT, 0x1f,
|
229
|
+
:PGP_SIG_REV_KEY, 0x20,
|
230
|
+
:PGP_SIG_REV_SUBKEY, 0x28,
|
231
|
+
:PGP_SIG_REV_CERT, 0x30,
|
232
|
+
:PGP_SIG_TIMESTAMP, 0x40,
|
233
|
+
:PGP_SIG_3RD_PARTY, 0x50
|
234
|
+
]
|
235
|
+
enum :pgp_litdata_enum, [
|
236
|
+
:PGP_LDT_BINARY, 'b'.ord,
|
237
|
+
:PGP_LDT_TEXT, 't'.ord,
|
238
|
+
:PGP_LDT_UTF8, 'u'.ord,
|
239
|
+
:PGP_LDT_LOCAL, 'l'.ord,
|
240
|
+
:PGP_LDT_LOCAL2, '1'.ord
|
241
|
+
]
|
242
|
+
end
|
243
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module LibC
|
4
|
+
extend FFI::Library
|
5
|
+
ffi_lib FFI::Library::LIBC
|
6
|
+
|
7
|
+
attach_function :calloc,
|
8
|
+
[:size_t, :size_t],
|
9
|
+
:pointer
|
10
|
+
attach_function :realloc,
|
11
|
+
[:pointer, :size_t],
|
12
|
+
:pointer
|
13
|
+
attach_function :free,
|
14
|
+
[:pointer],
|
15
|
+
:void
|
16
|
+
|
17
|
+
attach_function :memset,
|
18
|
+
[:pointer, :int, :size_t],
|
19
|
+
:pointer
|
20
|
+
|
21
|
+
attach_function :fdopen,
|
22
|
+
[:int, :string],
|
23
|
+
:pointer
|
24
|
+
attach_function :fclose,
|
25
|
+
[:pointer],
|
26
|
+
:int
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module LibOpenSSL
|
4
|
+
extend FFI::Library
|
5
|
+
ffi_lib ['ssl']
|
6
|
+
|
7
|
+
# Caller must free result with OPENSSL_free aka (usually) LIBC free
|
8
|
+
attach_function :BN_bn2hex,
|
9
|
+
[:pointer],
|
10
|
+
:strptr
|
11
|
+
attach_function :BN_hex2bn,
|
12
|
+
[:pointer, :string],
|
13
|
+
:int
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,213 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
require_relative 'enums'
|
4
|
+
require_relative 'structs'
|
5
|
+
|
6
|
+
module LibRNP
|
7
|
+
extend FFI::Library
|
8
|
+
ffi_lib ['rnp']
|
9
|
+
|
10
|
+
attach_function :pgp_parse_options,
|
11
|
+
[PGPStream.by_ref, :pgp_content_enum, :pgp_parse_type_t],
|
12
|
+
:void
|
13
|
+
attach_function :pgp_reader_set_fd,
|
14
|
+
[PGPStream.by_ref, :int],
|
15
|
+
:void
|
16
|
+
attach_function :pgp_reader_set_memory,
|
17
|
+
[PGPStream.by_ref, :pointer, :size_t],
|
18
|
+
:void
|
19
|
+
attach_function :pgp_set_callback,
|
20
|
+
[PGPStream.by_ref, :pgp_cbfunc_t, :pointer],
|
21
|
+
:void
|
22
|
+
attach_function :pgp_reader_push_dearmour,
|
23
|
+
[PGPStream.by_ref],
|
24
|
+
:void
|
25
|
+
attach_function :pgp_reader_pop_dearmour,
|
26
|
+
[PGPStream.by_ref],
|
27
|
+
:void
|
28
|
+
attach_function :pgp_parse_and_accumulate,
|
29
|
+
[PGPKeyring.by_ref, PGPStream.by_ref],
|
30
|
+
:int
|
31
|
+
attach_function :pgp_callback_push,
|
32
|
+
[PGPStream.by_ref, :pgp_cbfunc_t, :pointer],
|
33
|
+
:void
|
34
|
+
attach_function :pgp_parse,
|
35
|
+
[PGPStream.by_ref, :int],
|
36
|
+
:int
|
37
|
+
|
38
|
+
attach_function :pgp_rsa_new_selfsign_key,
|
39
|
+
[:int, :ulong, :string, :string, :string],
|
40
|
+
PGPKey.by_ref
|
41
|
+
attach_function :pgp_rsa_new_key,
|
42
|
+
[:int, :ulong, :string, :string],
|
43
|
+
PGPKey.by_ref
|
44
|
+
attach_function :pgp_keydata_free,
|
45
|
+
[:pointer],
|
46
|
+
:void
|
47
|
+
|
48
|
+
attach_function :pgp_add_userid,
|
49
|
+
[PGPKey.by_ref, :string],
|
50
|
+
:strptr
|
51
|
+
|
52
|
+
attach_function :pgp_add_selfsigned_userid,
|
53
|
+
[PGPKey.by_ref, :string],
|
54
|
+
:uint
|
55
|
+
|
56
|
+
attach_function :pgp_keyring_free,
|
57
|
+
[:pointer],
|
58
|
+
:void
|
59
|
+
attach_function :pgp_pubkey_free,
|
60
|
+
[:pointer],
|
61
|
+
:void
|
62
|
+
attach_function :pgp_seckey_free,
|
63
|
+
[:pointer],
|
64
|
+
:void
|
65
|
+
|
66
|
+
attach_function :pgp_keyring_fileread,
|
67
|
+
[PGPKeyring.by_ref, :uint, :string],
|
68
|
+
:uint
|
69
|
+
attach_function :pgp_keyring_read_from_mem,
|
70
|
+
[PGPIO.by_ref, PGPKeyring.by_ref, :uint, PGPMemory.by_ref],
|
71
|
+
:uint
|
72
|
+
|
73
|
+
attach_function :pgp_sign_file,
|
74
|
+
[PGPIO.by_ref, :string, :string, PGPSecKey.by_ref, :string, :int64, :uint64, :uint, :uint, :uint],
|
75
|
+
:uint
|
76
|
+
attach_function :pgp_sign_detached,
|
77
|
+
[PGPIO.by_ref, :string, :string, PGPSecKey.by_ref, :string, :int64, :uint64, :uint, :uint],
|
78
|
+
:int
|
79
|
+
attach_function :pgp_sign_buf,
|
80
|
+
[PGPIO.by_ref, :pointer, :size_t, PGPSecKey.by_ref, :int64, :uint64, :string, :uint, :uint],
|
81
|
+
:pointer
|
82
|
+
attach_function :pgp_validate_file,
|
83
|
+
[PGPIO.by_ref, PGPValidation.by_ref, :string, :string, :int, PGPKeyring.by_ref],
|
84
|
+
:uint
|
85
|
+
attach_function :pgp_validate_mem,
|
86
|
+
[PGPIO.by_ref, PGPValidation.by_ref, PGPMemory.by_ref, :pointer, :int, PGPKeyring.by_ref],
|
87
|
+
:uint
|
88
|
+
|
89
|
+
attach_function :pgp_encrypt_file,
|
90
|
+
[PGPIO.by_ref, :string, :string, PGPKey.by_ref, :uint, :uint, :string],
|
91
|
+
:uint
|
92
|
+
attach_function :pgp_encrypt_buf,
|
93
|
+
[PGPIO.by_ref, :pointer, :size_t, PGPKey.by_ref, :uint, :string],
|
94
|
+
:pointer
|
95
|
+
attach_function :pgp_decrypt_file,
|
96
|
+
[PGPIO.by_ref, :string, :string, PGPKeyring.by_ref, PGPKeyring.by_ref, :uint, :uint, :uint, :pointer, :int, :pgp_cbfunc_t],
|
97
|
+
:uint
|
98
|
+
attach_function :pgp_decrypt_buf,
|
99
|
+
[PGPIO.by_ref, :pointer, :size_t, PGPKeyring.by_ref, PGPKeyring.by_ref, :uint, :uint, :pointer, :int, :pgp_cbfunc_t],
|
100
|
+
:pointer
|
101
|
+
|
102
|
+
attach_function :pgp_export_key,
|
103
|
+
[PGPIO.by_ref, PGPKey.by_ref, :string],
|
104
|
+
:string
|
105
|
+
|
106
|
+
attach_function :pgp_memory_new,
|
107
|
+
[],
|
108
|
+
PGPMemory.by_ref
|
109
|
+
attach_function :pgp_memory_free,
|
110
|
+
[PGPMemory.by_ref],
|
111
|
+
:void
|
112
|
+
attach_function :pgp_memory_init,
|
113
|
+
[PGPMemory.by_ref, :size_t],
|
114
|
+
:void
|
115
|
+
attach_function :pgp_memory_pad,
|
116
|
+
[PGPMemory.by_ref, :size_t],
|
117
|
+
:void
|
118
|
+
attach_function :pgp_memory_add,
|
119
|
+
[PGPMemory.by_ref, :pointer, :size_t],
|
120
|
+
:void
|
121
|
+
attach_function :pgp_memory_place_int,
|
122
|
+
[PGPMemory.by_ref, :uint, :uint, :size_t],
|
123
|
+
:void
|
124
|
+
attach_function :pgp_memory_make_packet,
|
125
|
+
[PGPMemory.by_ref, :pgp_content_enum],
|
126
|
+
:void
|
127
|
+
attach_function :pgp_memory_clear,
|
128
|
+
[PGPMemory.by_ref],
|
129
|
+
:void
|
130
|
+
attach_function :pgp_memory_release,
|
131
|
+
[PGPMemory.by_ref],
|
132
|
+
:void
|
133
|
+
attach_function :pgp_mem_len,
|
134
|
+
[PGPMemory.by_ref],
|
135
|
+
:size_t
|
136
|
+
attach_function :pgp_mem_data,
|
137
|
+
[PGPMemory.by_ref],
|
138
|
+
:pointer
|
139
|
+
attach_function :pgp_mem_readfile,
|
140
|
+
[PGPMemory.by_ref, :string],
|
141
|
+
:int
|
142
|
+
|
143
|
+
attach_function :pgp_is_key_secret,
|
144
|
+
[PGPKey.by_ref],
|
145
|
+
:uint
|
146
|
+
attach_function :pgp_get_seckey,
|
147
|
+
[PGPKey.by_ref],
|
148
|
+
:pointer
|
149
|
+
attach_function :pgp_decrypt_seckey,
|
150
|
+
[PGPKey.by_ref, :pointer],
|
151
|
+
:pointer
|
152
|
+
|
153
|
+
attach_function :pgp_stream_delete,
|
154
|
+
[:pointer],
|
155
|
+
:void
|
156
|
+
|
157
|
+
attach_function :pgp_setup_memory_write,
|
158
|
+
[:pointer, :pointer, :size_t],
|
159
|
+
:void
|
160
|
+
attach_function :pgp_teardown_memory_write,
|
161
|
+
[PGPOutput.by_ref, PGPMemory.by_ref],
|
162
|
+
:void
|
163
|
+
attach_function :pgp_write_xfer_pubkey,
|
164
|
+
[PGPOutput.by_ref, PGPKey.by_ref, :pointer, :uint],
|
165
|
+
:uint
|
166
|
+
attach_function :pgp_write_xfer_seckey,
|
167
|
+
[PGPOutput.by_ref, PGPKey.by_ref, :pointer, :size_t, :pointer, :uint],
|
168
|
+
:uint
|
169
|
+
|
170
|
+
attach_function :pgp_create_sig_new,
|
171
|
+
[],
|
172
|
+
:pointer
|
173
|
+
attach_function :pgp_create_sig_delete,
|
174
|
+
[:pointer],
|
175
|
+
:void
|
176
|
+
attach_function :pgp_sig_start_key_sig,
|
177
|
+
[:pointer, PGPPubKey.by_ref, :string, :pgp_sig_type_t],
|
178
|
+
:void
|
179
|
+
attach_function :pgp_sig_start_subkey_sig,
|
180
|
+
[:pointer, PGPPubKey.by_ref, PGPPubKey.by_ref, :pgp_sig_type_t],
|
181
|
+
:void
|
182
|
+
attach_function :pgp_write_sig,
|
183
|
+
[PGPOutput.by_ref, :pointer, PGPPubKey.by_ref, PGPSecKey.by_ref],
|
184
|
+
:uint
|
185
|
+
attach_function :pgp_add_time,
|
186
|
+
[:pointer, :int64, :string],
|
187
|
+
:uint
|
188
|
+
attach_function :pgp_add_issuer_keyid,
|
189
|
+
[:pointer, :pointer],
|
190
|
+
:uint
|
191
|
+
attach_function :pgp_end_hashed_subpkts,
|
192
|
+
[:pointer],
|
193
|
+
:uint
|
194
|
+
|
195
|
+
attach_function :pgp_add_subpacket,
|
196
|
+
[PGPKey.by_ref, PGPSubPacket.by_ref],
|
197
|
+
:pointer
|
198
|
+
|
199
|
+
attach_function :pgp_fingerprint,
|
200
|
+
[PGPFingerprint.by_ref, PGPPubKey.by_ref, :pgp_hash_alg_t],
|
201
|
+
:int
|
202
|
+
attach_function :pgp_keyid,
|
203
|
+
[:pointer, :size_t, PGPPubKey.by_ref, :pgp_hash_alg_t],
|
204
|
+
:int
|
205
|
+
|
206
|
+
attach_function :pgp_writer_close,
|
207
|
+
[PGPOutput.by_ref],
|
208
|
+
:uint
|
209
|
+
attach_function :pgp_output_delete,
|
210
|
+
[PGPOutput.by_ref],
|
211
|
+
:void
|
212
|
+
end
|
213
|
+
|