blob: c1105ebf81cc0015d6e05b316f29e3ef9b14bf45 (
plain)
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
|
/* Copyright (c) 1999-2002 Ng Pheng Siong. All rights reserved.
* Copyright (c) 2009-2010 Heikki Toivonen. All rights reserved.
*/
/* $Id$ */
%{
#include <openssl/x509v3.h>
%}
%inline %{
static PyObject *_util_err;
void util_init(PyObject *util_err) {
Py_INCREF(util_err);
_util_err = util_err;
}
PyObject *util_hex_to_string(PyObject *blob) {
PyObject *obj;
const void *buf;
char *ret;
Py_ssize_t len;
if (PyObject_AsReadBuffer(blob, &buf, &len) == -1)
return NULL;
ret = hex_to_string((unsigned char *)buf, len);
if (!ret) {
PyErr_SetString(_util_err, ERR_reason_error_string(ERR_get_error()));
return NULL;
}
obj = PyString_FromString(ret);
OPENSSL_free(ret);
return obj;
}
PyObject *util_string_to_hex(PyObject *blob) {
PyObject *obj;
const void *buf;
unsigned char *ret;
Py_ssize_t len0;
long len;
if (PyObject_AsReadBuffer(blob, &buf, &len0) == -1)
return NULL;
len = len0;
ret = string_to_hex((char *)buf, &len);
if (ret == NULL) {
PyErr_SetString(_util_err, ERR_reason_error_string(ERR_get_error()));
return NULL;
}
obj = PyString_FromStringAndSize((char*)ret, len);
OPENSSL_free(ret);
return obj;
}
%}
|