Ruby
1.9.3p551(2014-11-13revision48407)
Main Page
Modules
Data Structures
Files
File List
Globals
ext
openssl
ossl_pkey.h
Go to the documentation of this file.
1
/*
2
* $Id: ossl_pkey.h 31556 2011-05-13 20:10:27Z emboss $
3
* 'OpenSSL for Ruby' project
4
* Copyright (C) 2001 Michal Rokos <m.rokos@sh.cvut.cz>
5
* All rights reserved.
6
*/
7
/*
8
* This program is licenced under the same licence as Ruby.
9
* (See the file 'LICENCE'.)
10
*/
11
#if !defined(_OSSL_PKEY_H_)
12
#define _OSSL_PKEY_H_
13
14
extern
VALUE
mPKey
;
15
extern
VALUE
cPKey
;
16
extern
VALUE
ePKeyError
;
17
extern
ID
id_private_q
;
18
19
#define OSSL_PKEY_SET_PRIVATE(obj) rb_iv_set((obj), "private", Qtrue)
20
#define OSSL_PKEY_SET_PUBLIC(obj) rb_iv_set((obj), "private", Qfalse)
21
#define OSSL_PKEY_IS_PRIVATE(obj) (rb_iv_get((obj), "private") == Qtrue)
22
23
#define WrapPKey(klass, obj, pkey) do { \
24
if (!(pkey)) { \
25
rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!"); \
26
} \
27
(obj) = Data_Wrap_Struct((klass), 0, EVP_PKEY_free, (pkey)); \
28
OSSL_PKEY_SET_PUBLIC(obj); \
29
} while (0)
30
#define GetPKey(obj, pkey) do {\
31
Data_Get_Struct((obj), EVP_PKEY, (pkey));\
32
if (!(pkey)) { \
33
rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!");\
34
} \
35
} while (0)
36
#define SafeGetPKey(obj, pkey) do { \
37
OSSL_Check_Kind((obj), cPKey); \
38
GetPKey((obj), (pkey)); \
39
} while (0)
40
41
void
ossl_generate_cb
(
int
,
int
,
void
*);
42
43
VALUE
ossl_pkey_new
(EVP_PKEY *);
44
VALUE
ossl_pkey_new_from_file
(
VALUE
);
45
EVP_PKEY *
GetPKeyPtr
(
VALUE
);
46
EVP_PKEY *
DupPKeyPtr
(
VALUE
);
47
EVP_PKEY *
GetPrivPKeyPtr
(
VALUE
);
48
EVP_PKEY *
DupPrivPKeyPtr
(
VALUE
);
49
void
Init_ossl_pkey
(
void
);
50
51
/*
52
* RSA
53
*/
54
extern
VALUE
cRSA
;
55
extern
VALUE
eRSAError
;
56
57
VALUE
ossl_rsa_new
(EVP_PKEY *);
58
void
Init_ossl_rsa
(
void
);
59
60
/*
61
* DSA
62
*/
63
extern
VALUE
cDSA
;
64
extern
VALUE
eDSAError
;
65
66
VALUE
ossl_dsa_new
(EVP_PKEY *);
67
void
Init_ossl_dsa
(
void
);
68
69
/*
70
* DH
71
*/
72
extern
VALUE
cDH
;
73
extern
VALUE
eDHError
;
74
extern
DH *
OSSL_DEFAULT_DH_512
;
75
extern
DH *
OSSL_DEFAULT_DH_1024
;
76
77
VALUE
ossl_dh_new
(EVP_PKEY *);
78
void
Init_ossl_dh
(
void
);
79
80
/*
81
* EC
82
*/
83
extern
VALUE
cEC
;
84
extern
VALUE
eECError
;
85
extern
VALUE
cEC_GROUP
;
86
extern
VALUE
eEC_GROUP
;
87
extern
VALUE
cEC_POINT
;
88
extern
VALUE
eEC_POINT
;
89
VALUE
ossl_ec_new
(EVP_PKEY *);
90
void
Init_ossl_ec
(
void
);
91
92
93
#define OSSL_PKEY_BN(keytype, name) \
94
/* \
95
* call-seq: \
96
* key.##name -> aBN \
97
*/
\
98
static VALUE ossl_##keytype##_get_##name(VALUE self) \
99
{ \
100
EVP_PKEY *pkey; \
101
BIGNUM *bn; \
102
\
103
GetPKey(self, pkey); \
104
bn = pkey->pkey.keytype->name; \
105
if (bn == NULL) \
106
return Qnil; \
107
return ossl_bn_new(bn); \
108
} \
109
/* \
110
* call-seq: \
111
* key.##name = bn -> bn \
112
*/
\
113
static VALUE ossl_##keytype##_set_##name(VALUE self, VALUE bignum) \
114
{ \
115
EVP_PKEY *pkey; \
116
BIGNUM *bn; \
117
\
118
GetPKey(self, pkey); \
119
if (NIL_P(bignum)) { \
120
BN_clear_free(pkey->pkey.keytype->name); \
121
pkey->pkey.keytype->name = NULL; \
122
return Qnil; \
123
} \
124
\
125
bn = GetBNPtr(bignum); \
126
if (pkey->pkey.keytype->name == NULL) \
127
pkey->pkey.keytype->name = BN_new(); \
128
if (pkey->pkey.keytype->name == NULL) \
129
ossl_raise(eBNError, NULL); \
130
if (BN_copy(pkey->pkey.keytype->name, bn) == NULL) \
131
ossl_raise(eBNError, NULL); \
132
return bignum; \
133
}
134
135
#define DEF_OSSL_PKEY_BN(class, keytype, name) \
136
do { \
137
rb_define_method((class), #name, ossl_##keytype##_get_##name, 0); \
138
rb_define_method((class), #name "=", ossl_##keytype##_set_##name, 1);\
139
} while (0)
140
141
#endif
/* _OSSL_PKEY_H_ */
142
Generated on Fri Nov 14 2014 16:04:00 for Ruby by
1.8.3