-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPyEnrollContainerKey.cpp
More file actions
159 lines (144 loc) · 6.71 KB
/
PyEnrollContainerKey.cpp
File metadata and controls
159 lines (144 loc) · 6.71 KB
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
#include "PyEnrollContainerKey.h"
#include "PyCadesCertificate.h"
#include "PyCadesPublicKey.h"
using namespace CryptoPro::PKI::Enroll;
static void ContainerKey_dealloc(ContainerKey *self)
{
self->m_pCppEnrollImpl.reset();
Py_TYPE(self)->tp_free((PyObject *)self);
}
static PyObject *ContainerKey_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
ContainerKey *self;
self = (ContainerKey *)type->tp_alloc(type, 0);
if (self != NULL)
{
self->m_pCppEnrollImpl = NS_SHARED_PTR::shared_ptr<CPPEnrollContainerKey>(new CPPEnrollContainerKey());
}
return (PyObject *)self;
}
static PyObject *ContainerKey_getIsExportable(ContainerKey *self)
{
BOOL bValue;
HR_METHOD_ERRORCHECK_RETURN(self->m_pCppEnrollImpl->get_IsExportable(bValue));
if (bValue)
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
static PyObject *ContainerKey_getHasCertificate(ContainerKey *self)
{
BOOL bValue;
HR_METHOD_ERRORCHECK_RETURN(self->m_pCppEnrollImpl->get_HasCertificate(bValue));
if (bValue)
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
static PyObject *ContainerKey_getType(ContainerKey *self)
{
DWORD dwValue;
HR_METHOD_ERRORCHECK_RETURN(self->m_pCppEnrollImpl->get_Type(dwValue));
return Py_BuildValue("l", dwValue);
}
static PyObject *ContainerKey_getCertificate(ContainerKey *self)
{
NS_SHARED_PTR::shared_ptr<CPPCadesCPCertificateObject> pCPPCadesCPCert;
HR_METHOD_ERRORCHECK_RETURN(self->m_pCppEnrollImpl->get_Certificate(pCPPCadesCPCert));
PyObject *pPyCertificate = PyObject_CallObject((PyObject *)&CertificateType, NULL);
Certificate *pCertificate = (Certificate *)pPyCertificate;
pCertificate->m_pCppCadesImpl = pCPPCadesCPCert;
return Py_BuildValue("N", pCertificate);
}
#if IS_CADES_VERSION_GREATER_EQUAL(2, 0, 15000)
static PyObject *ContainerKey_getPublicKey(ContainerKey *self)
{
NS_SHARED_PTR::shared_ptr<CPPCadesCPPublicKeyObject> pCPPCadesPublicKey;
HR_METHOD_ERRORCHECK_RETURN(self->m_pCppEnrollImpl->get_PublicKey(pCPPCadesPublicKey));
PyObject *pPyPublicKey = PyObject_CallObject((PyObject *)&PublicKeyType, NULL);
PublicKey *pPublicKey = (PublicKey *)pPyPublicKey;
pPublicKey->m_pCppCadesImpl = pCPPCadesPublicKey;
return Py_BuildValue("N", pPublicKey);
}
static PyObject *ContainerKey_getKP_FP(ContainerKey *self)
{
CAtlString sValue;
HR_METHOD_ERRORCHECK_RETURN(self->m_pCppEnrollImpl->get_KP_FP(sValue));
return Py_BuildValue("s", sValue.GetString());
}
#endif
#if IS_CADES_VERSION_GREATER_EQUAL(2, 0, 15400)
static PyObject *ContainerKey_getKP_ALGID(ContainerKey *self)
{
DWORD dwValue;
HR_METHOD_ERRORCHECK_RETURN(self->m_pCppEnrollImpl->get_KP_ALGID(dwValue));
return Py_BuildValue("l", dwValue);
}
#endif
static PyObject *ContainerKey_getExpirationTime(ContainerKey *self)
{
CryptoPro::CDateTime date;
CryptoPro::CStringProxy strProxyDate;
HR_METHOD_ERRORCHECK_RETURN(self->m_pCppEnrollImpl->get_ExpirationTime(date));
strProxyDate = date.tostring();
return Py_BuildValue("s", strProxyDate.c_str());
}
static PyGetSetDef ContainerKey_getset[] = {
{"IsExportable", (getter)ContainerKey_getIsExportable, NULL, "IsExportable", NULL},
{"HasCertificate", (getter)ContainerKey_getHasCertificate, NULL, "HasCertificate", NULL},
{"Type", (getter)ContainerKey_getType, NULL, "Type", NULL},
{"Certificate", (getter)ContainerKey_getCertificate, NULL, "Certificate", NULL},
{"ExpirationTime", (getter)ContainerKey_getExpirationTime, NULL, "ExpirationTime", NULL},
#if IS_CADES_VERSION_GREATER_EQUAL(2, 0, 15000)
{"PublicKey", (getter)ContainerKey_getPublicKey, NULL, "PublicKey", NULL},
{"KP_FP", (getter)ContainerKey_getKP_FP, NULL, "KP_FP", NULL},
#endif
#if IS_CADES_VERSION_GREATER_EQUAL(2, 0, 15400)
{"KP_ALGID", (getter)ContainerKey_getKP_ALGID, NULL, "KP_ALGID", NULL},
#endif
{NULL} /* Sentinel */
};
static PyMethodDef ContainerKey_methods[] = {
{NULL} /* Sentinel */
};
PyTypeObject ContainerKeyType = {
PyVarObject_HEAD_INIT(NULL, 0) "pycades.ContainerKey", /* tp_name */
sizeof(ContainerKey), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)ContainerKey_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
"ContainerKey object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ContainerKey_methods, /* tp_methods */
0, /* tp_members */
ContainerKey_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
ContainerKey_new, /* tp_new */
};