1 | /* |
---|---|
2 | trustitem.cpp - wraps a gpgme trust item |
3 | Copyright (C) 2003 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++/trustitem.h> |
26 | |
27 | #include <gpgme.h> |
28 | |
29 | #include <cassert> |
30 | |
31 | namespace GpgME { |
32 | |
33 | class TrustItem::Private { |
34 | public: |
35 | Private( gpgme_trust_item_t aItem ) |
36 | : item( aItem ) |
37 | { |
38 | } |
39 | |
40 | gpgme_trust_item_t item; |
41 | }; |
42 | |
43 | TrustItem::TrustItem( gpgme_trust_item_t item ) { |
44 | d = new Private( item ); |
45 | if ( d->item ) { |
46 | gpgme_trust_item_ref( d->item ); |
47 | } |
48 | } |
49 | |
50 | TrustItem::TrustItem( const TrustItem & other ) { |
51 | d = new Private( other.d->item ); |
52 | if ( d->item ) { |
53 | gpgme_trust_item_ref( d->item ); |
54 | } |
55 | } |
56 | |
57 | TrustItem::~TrustItem() { |
58 | if ( d->item ) { |
59 | gpgme_trust_item_unref( d->item ); |
60 | } |
61 | delete d; d = 0; |
62 | } |
63 | |
64 | bool TrustItem::isNull() const { |
65 | return !d || !d->item; |
66 | } |
67 | |
68 | gpgme_trust_item_t TrustItem::impl() const { |
69 | return d->item; |
70 | } |
71 | |
72 | |
73 | const char * TrustItem::keyID() const { |
74 | return d->item ? d->item->keyid : 0 ; |
75 | } |
76 | |
77 | const char * TrustItem::userID() const { |
78 | return d->item ? d->item->name : 0 ; |
79 | } |
80 | |
81 | const char * TrustItem::ownerTrustAsString() const { |
82 | return d->item ? d->item->owner_trust : 0 ; |
83 | } |
84 | |
85 | const char * TrustItem::validityAsString() const { |
86 | return d->item ? d->item->validity : 0 ; |
87 | } |
88 | |
89 | int TrustItem::trustLevel() const { |
90 | return d->item ? d->item->level : 0 ; |
91 | } |
92 | |
93 | TrustItem::Type TrustItem::type() const { |
94 | if ( !d->item ) { |
95 | return Unknown; |
96 | } else { |
97 | return |
98 | d->item->type == 1 ? Key : |
99 | d->item->type == 2 ? UserID : |
100 | Unknown ; |
101 | } |
102 | } |
103 | |
104 | } // namespace GpgME |
105 |