1/*
2 keygenerationresult.cpp - wraps a gpgme keygen result
3 Copyright (C) 2004 Klarälvdalens Datakonsult AB
4
5 This file is part of GPGME++.
6
7 GPGME++ is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 GPGME++ is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with GPGME++; see the file COPYING.LIB. If not, write to the
19 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22
23#include <gpgme++/config-gpgme++.h>
24
25#include <gpgme++/keygenerationresult.h>
26#include "result_p.h"
27
28#include <gpgme.h>
29
30#include <cstring>
31#include <cstdlib>
32
33#include <string.h>
34
35class GpgME::KeyGenerationResult::Private {
36public:
37 Private( const _gpgme_op_genkey_result & r ) : res( r ) {
38 if ( res.fpr ) {
39 res.fpr = strdup( res.fpr );
40 }
41 }
42 ~Private() {
43 if ( res.fpr ) {
44 std::free( res.fpr );
45 }
46 res.fpr = 0;
47 }
48
49 _gpgme_op_genkey_result res;
50};
51
52GpgME::KeyGenerationResult::KeyGenerationResult( gpgme_ctx_t ctx, int error )
53 : GpgME::Result( error ), d()
54{
55 init( ctx );
56}
57
58GpgME::KeyGenerationResult::KeyGenerationResult( gpgme_ctx_t ctx, const Error & error )
59 : GpgME::Result( error ), d()
60{
61 init( ctx );
62}
63
64void GpgME::KeyGenerationResult::init( gpgme_ctx_t ctx ) {
65 if ( !ctx ) {
66 return;
67 }
68 gpgme_genkey_result_t res = gpgme_op_genkey_result( ctx );
69 if ( !res ) {
70 return;
71 }
72 d.reset( new Private( *res ) );
73}
74
75make_standard_stuff(KeyGenerationResult)
76
77bool GpgME::KeyGenerationResult::isPrimaryKeyGenerated() const {
78 return d && d->res.primary;
79}
80
81bool GpgME::KeyGenerationResult::isSubkeyGenerated() const {
82 return d && d->res.sub;
83}
84
85const char * GpgME::KeyGenerationResult::fingerprint() const {
86 return d ? d->res.fpr : 0 ;
87}
88