~launchpad-pqm/pygpgme/devel

« back to all changes in this revision

Viewing changes to src/pygpgme-genkey.c

  • Committer: Launchpad Patch Queue Manager
  • Date: 2008-10-22 21:47:47 UTC
  • mfrom: (47.1.1 pygpgme-genkey)
  • Revision ID: launchpad@pqm.canonical.com-20081022214747-h2sphj9zcuh1c1cq
[r=gmb] Merging trunk. Support for key generation and minor fixes in
        the test suite (GPG_AGENT_INFO handling).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
 
2
/*
 
3
    pygpgme - a Python wrapper for the gpgme library
 
4
    Copyright (C) 2006  James Henstridge
 
5
 
 
6
    This library is free software; you can redistribute it and/or
 
7
    modify it under the terms of the GNU Lesser General Public
 
8
    License as published by the Free Software Foundation; either
 
9
    version 2.1 of the License, or (at your option) any later version.
 
10
 
 
11
    This library is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
    Lesser General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU Lesser General Public
 
17
    License along with this library; if not, write to the Free Software
 
18
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
#include "pygpgme.h"
 
21
#include <structmember.h>
 
22
 
 
23
static void
 
24
pygpgme_genkey_result_dealloc(PyGpgmeGenkeyResult *self)
 
25
{
 
26
    Py_XDECREF(self->primary);
 
27
    Py_XDECREF(self->sub);
 
28
    Py_XDECREF(self->fpr);
 
29
    PyObject_Del(self);
 
30
}
 
31
 
 
32
static PyMemberDef pygpgme_genkey_result_members[] = {
 
33
    { "primary", T_OBJECT, offsetof(PyGpgmeGenkeyResult, primary), RO},
 
34
    { "sub", T_OBJECT, offsetof(PyGpgmeGenkeyResult, sub), RO},
 
35
    { "fpr", T_OBJECT, offsetof(PyGpgmeGenkeyResult, fpr), RO},
 
36
    { NULL, 0, 0, 0}
 
37
};
 
38
 
 
39
PyTypeObject PyGpgmeGenkeyResult_Type = {
 
40
    PyObject_HEAD_INIT(NULL)
 
41
    0,
 
42
    "gpgme.GenkeyResult",
 
43
    sizeof(PyGpgmeGenkeyResult),
 
44
    .tp_flags = Py_TPFLAGS_DEFAULT,
 
45
    .tp_init = pygpgme_no_constructor,
 
46
    .tp_dealloc = (destructor)pygpgme_genkey_result_dealloc,
 
47
    .tp_members = pygpgme_genkey_result_members,
 
48
};
 
49
 
 
50
PyObject *
 
51
pygpgme_genkey_result(gpgme_ctx_t ctx)
 
52
{
 
53
    gpgme_genkey_result_t result;
 
54
    PyGpgmeGenkeyResult *self;
 
55
 
 
56
    result = gpgme_op_genkey_result(ctx);
 
57
 
 
58
    if (result == NULL)
 
59
        Py_RETURN_NONE;
 
60
 
 
61
    self = PyObject_New(PyGpgmeGenkeyResult, &PyGpgmeGenkeyResult_Type);
 
62
    if (!self)
 
63
        return NULL;
 
64
 
 
65
    self->primary = PyBool_FromLong(result->primary);
 
66
    self->sub = PyBool_FromLong(result->sub);
 
67
    if (result->fpr)
 
68
        self->fpr = PyString_FromString(result->fpr);
 
69
    else {
 
70
        Py_INCREF(Py_None);
 
71
        self->fpr = Py_None;
 
72
    }
 
73
 
 
74
    return (PyObject *) self;
 
75
}