certmanager

hierarchyanalyser.cpp
1 /*
2  hierarchyanalyser.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2004 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra 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 GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the TQt library by Trolltech AS, Norway (or with modified versions
24  of TQt that use the same license as TQt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  TQt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #endif
36 
37 #include "hierarchyanalyser.h"
38 
39 #include <algorithm>
40 #include <iterator>
41 
42 HierarchyAnalyser::HierarchyAnalyser( TQObject * parent, const char * name )
43  : TQObject( parent, name )
44 {
45 
46 }
47 
48 HierarchyAnalyser::~HierarchyAnalyser() {
49 
50 }
51 
52 void HierarchyAnalyser::slotNextKey( const GpgME::Key & key ) {
53  if ( key.isNull() )
54  return;
55  if ( key.isRoot() || !key.chainID() || !*key.chainID() )
56  // root keys have themselves as issuer - we don't want them to
57  // have parents, though:
58  mSubjectsByIssuer[0].push_back( key );
59  else
60  mSubjectsByIssuer[key.chainID()].push_back( key );
61 }
62 
63 const std::vector<GpgME::Key> & HierarchyAnalyser::subjectsForIssuer( const char * issuer_dn ) const {
64  static const std::vector<GpgME::Key> empty;
65  std::map< TQCString, std::vector<GpgME::Key> >::const_iterator it =
66  mSubjectsByIssuer.find( issuer_dn );
67  return it == mSubjectsByIssuer.end() ? empty : it->second ;
68 }
69 
70 std::vector<GpgME::Key> HierarchyAnalyser::subjectsForIssuerRecursive( const char * issuer_dn ) const {
71  std::vector<GpgME::Key> keys = subjectsForIssuer( issuer_dn );
72  for ( unsigned int i = 0 ; i < keys.size() ; ++i ) // can't use iterators here, since appending would invalidate them
73  if ( const char * fpr = keys[i].primaryFingerprint() ) {
74  const std::vector<GpgME::Key> & tmp = subjectsForIssuer( fpr );
75  std::copy( tmp.begin(), tmp.end(), std::back_inserter( keys ) );
76  }
77  return keys;
78 }
79 
80 
81 #include "hierarchyanalyser.moc"