~ubuntu-branches/ubuntu/oneiric/xca/oneiric

« back to all changes in this revision

Viewing changes to lib/pki_x509super.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Tino Keitel
  • Date: 2009-09-14 20:55:44 UTC
  • Revision ID: james.westby@ubuntu.com-20090914205544-l4qsm2tjimhd62vo
Tags: upstream-0.7.0
ImportĀ upstreamĀ versionĀ 0.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vi: set sw=4 ts=4:
 
2
 *
 
3
 * Copyright (C) 2001 - 2007 Christian Hohnstaedt.
 
4
 *
 
5
 * All rights reserved.
 
6
 */
 
7
 
 
8
#include "pki_x509super.h"
 
9
 
 
10
pki_x509super::pki_x509super(const QString name)
 
11
        : pki_base(name)
 
12
{
 
13
        privkey = NULL;
 
14
}
 
15
 
 
16
pki_x509super::~pki_x509super()
 
17
{
 
18
        if (privkey)
 
19
                privkey->decUcount();
 
20
        privkey = NULL;
 
21
}
 
22
 
 
23
pki_key *pki_x509super::getRefKey() const
 
24
{
 
25
        return privkey;
 
26
}
 
27
 
 
28
void pki_x509super::setRefKey(pki_key *ref)
 
29
{
 
30
        if (ref == NULL || ref->isPubKey() || privkey != NULL )
 
31
                return;
 
32
        pki_key *mk = getPubKey();
 
33
        if (ref->compare(mk)) {
 
34
                // this is our key
 
35
                privkey = ref;
 
36
                ref->incUcount();
 
37
        }
 
38
        delete mk;
 
39
}
 
40
 
 
41
void pki_x509super::delRefKey(pki_key *ref)
 
42
{
 
43
        if (ref != privkey || ref == NULL)
 
44
                return;
 
45
        ref->decUcount();
 
46
        privkey = NULL;
 
47
}
 
48
 
 
49
void pki_x509super::autoIntName()
 
50
{
 
51
        int nids[] = { NID_commonName, NID_pkcs9_emailAddress,
 
52
                        NID_organizationalUnitName, NID_organizationName, NID_undef };
 
53
        int i;
 
54
        x509name subject = getSubject();
 
55
        QString s;
 
56
 
 
57
        for (i = 0; nids[i] != NID_undef; i++) {
 
58
                s = subject.getEntryByNid(nids[i]);
 
59
                if (!s.isEmpty())
 
60
                        break;
 
61
        }
 
62
        if (s.isEmpty())
 
63
                s = subject.getEntry(-1);
 
64
        setIntName(s);
 
65
}