-
Notifications
You must be signed in to change notification settings - Fork 0
/
PHPCadesCPKeyUsage.cpp
220 lines (175 loc) · 5.91 KB
/
PHPCadesCPKeyUsage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "stdafx.h"
#include "PHPCadesCPKeyUsage.h"
using namespace CryptoPro::PKI::CAdES;
PHP_METHOD(CPKeyUsage, __construct) {
ku_obj *obj = (ku_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
obj->m_pCppCadesImpl = boost::shared_ptr<CPPCadesCPKeyUsageObject>(
new CPPCadesCPKeyUsageObject());
}
PHP_METHOD(CPKeyUsage, get_IsPresent) {
BOOL val;
ku_obj *obj = (ku_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
HR_ERRORCHECK_RETURN(obj->m_pCppCadesImpl->get_IsPresent(&val));
if (val) {
RETURN_TRUE
} else {
RETURN_FALSE
}
}
PHP_METHOD(CPKeyUsage, get_IsCritical) {
BOOL val;
ku_obj *obj = (ku_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
HR_ERRORCHECK_RETURN(obj->m_pCppCadesImpl->get_IsCritical(&val));
if (val) {
RETURN_TRUE
} else {
RETURN_FALSE
}
}
PHP_METHOD(CPKeyUsage, get_IsDigitalSignatureEnabled) {
BOOL val;
ku_obj *obj = (ku_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
HR_ERRORCHECK_RETURN(
obj->m_pCppCadesImpl->get_IsDigitalSignatureEnabled(&val));
if (val) {
RETURN_TRUE
} else {
RETURN_FALSE
}
}
PHP_METHOD(CPKeyUsage, get_IsNonRepudiationEnabled) {
BOOL val;
ku_obj *obj = (ku_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
HR_ERRORCHECK_RETURN(
obj->m_pCppCadesImpl->get_IsNonRepudiationEnabled(&val));
if (val) {
RETURN_TRUE
} else {
RETURN_FALSE
}
}
PHP_METHOD(CPKeyUsage, get_IsKeyEnciphermentEnabled) {
BOOL val;
ku_obj *obj = (ku_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
HR_ERRORCHECK_RETURN(
obj->m_pCppCadesImpl->get_IsKeyEnciphermentEnabled(&val));
if (val) {
RETURN_TRUE
} else {
RETURN_FALSE
}
}
PHP_METHOD(CPKeyUsage, get_IsDataEnciphermentEnabled) {
BOOL val;
ku_obj *obj = (ku_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
HR_ERRORCHECK_RETURN(
obj->m_pCppCadesImpl->get_IsDataEnciphermentEnabled(&val));
if (val) {
RETURN_TRUE
} else {
RETURN_FALSE
}
}
PHP_METHOD(CPKeyUsage, get_IsKeyAgreementEnabled) {
BOOL val;
ku_obj *obj = (ku_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
HR_ERRORCHECK_RETURN(obj->m_pCppCadesImpl->get_IsKeyAgreementEnabled(&val));
if (val) {
RETURN_TRUE
} else {
RETURN_FALSE
}
}
PHP_METHOD(CPKeyUsage, get_IsKeyCertSignEnabled) {
BOOL val;
ku_obj *obj = (ku_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
HR_ERRORCHECK_RETURN(obj->m_pCppCadesImpl->get_IsKeyCertSignEnabled(&val));
if (val) {
RETURN_TRUE
} else {
RETURN_FALSE
}
}
PHP_METHOD(CPKeyUsage, get_IsCRLSignEnabled) {
BOOL val;
ku_obj *obj = (ku_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
HR_ERRORCHECK_RETURN(obj->m_pCppCadesImpl->get_IsCRLSignEnabled(&val));
if (val) {
RETURN_TRUE
} else {
RETURN_FALSE
}
}
PHP_METHOD(CPKeyUsage, get_IsEncipherOnlyEnabled) {
BOOL val;
ku_obj *obj = (ku_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
HR_ERRORCHECK_RETURN(obj->m_pCppCadesImpl->get_IsEncipherOnlyEnabled(&val));
if (val) {
RETURN_TRUE
} else {
RETURN_FALSE
}
}
PHP_METHOD(CPKeyUsage, get_IsDecipherOnlyEnabled) {
BOOL val;
ku_obj *obj = (ku_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
HR_ERRORCHECK_RETURN(obj->m_pCppCadesImpl->get_IsDecipherOnlyEnabled(&val));
if (val) {
RETURN_TRUE
} else {
RETURN_FALSE
}
}
zend_object_handlers ku_obj_handlers;
zend_class_entry *ku_ce;
void ku_free_storage(void *object TSRMLS_DC) {
ku_obj *obj = (ku_obj *)object;
obj->m_pCppCadesImpl.reset();
zend_hash_destroy(obj->zo.properties);
FREE_HASHTABLE(obj->zo.properties);
efree(obj);
}
zend_object_value ku_create_handler(zend_class_entry *type TSRMLS_DC) {
zend_object_value retval;
ku_obj *obj = (ku_obj *)emalloc(sizeof(ku_obj));
memset(obj, 0, sizeof(ku_obj));
obj->zo.ce = type;
ALLOC_HASHTABLE(obj->zo.properties);
zend_hash_init(obj->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
#if PHP_VERSION_ID < 50399
zval *tmp;
zend_hash_copy(obj->zo.properties, &(type->default_properties),
(copy_ctor_func_t)zval_add_ref, (void *)&tmp,
sizeof(zval *));
#else
object_properties_init(&obj->zo, type);
#endif
retval.handle =
zend_objects_store_put(obj, NULL, ku_free_storage, NULL TSRMLS_CC);
retval.handlers = &ku_obj_handlers;
return retval;
}
//ñâÿçûâàíèå ìåòîäîâ êëàññà â function entry
zend_function_entry ku_methods[] = {
PHP_ME(CPKeyUsage, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(CPKeyUsage, get_IsPresent, NULL, ZEND_ACC_PUBLIC)
PHP_ME(CPKeyUsage, get_IsCritical, NULL, ZEND_ACC_PUBLIC)
PHP_ME(CPKeyUsage, get_IsDigitalSignatureEnabled, NULL, ZEND_ACC_PUBLIC)
PHP_ME(CPKeyUsage, get_IsNonRepudiationEnabled, NULL, ZEND_ACC_PUBLIC)
PHP_ME(CPKeyUsage, get_IsKeyEnciphermentEnabled, NULL, ZEND_ACC_PUBLIC)
PHP_ME(CPKeyUsage, get_IsDataEnciphermentEnabled, NULL, ZEND_ACC_PUBLIC)
PHP_ME(CPKeyUsage, get_IsKeyAgreementEnabled, NULL, ZEND_ACC_PUBLIC)
PHP_ME(CPKeyUsage, get_IsKeyCertSignEnabled, NULL, ZEND_ACC_PUBLIC)
PHP_ME(CPKeyUsage, get_IsCRLSignEnabled, NULL, ZEND_ACC_PUBLIC)
PHP_ME(CPKeyUsage, get_IsEncipherOnlyEnabled, NULL, ZEND_ACC_PUBLIC)
PHP_ME(CPKeyUsage, get_IsDecipherOnlyEnabled, NULL,
ZEND_ACC_PUBLIC){NULL, NULL, NULL}};
void ku_init(TSRMLS_D) {
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "CPKeyUsage", ku_methods);
ku_ce = zend_register_internal_class(&ce TSRMLS_CC);
ku_ce->create_object = ku_create_handler;
memcpy(&ku_obj_handlers, zend_get_std_object_handlers(),
sizeof(zend_object_handlers));
ku_obj_handlers.clone_obj = NULL;
}