• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkpgp

  • sources
  • kde-4.14
  • kdepim
  • libkpgp
kpgpblock.cpp
Go to the documentation of this file.
1 /*
2  kpgpblock.cpp
3 
4  Copyright (C) 2001,2002 the KPGP authors
5  See file AUTHORS.kpgp for details
6 
7  This file is part of KPGP, the KDE PGP/GnuPG support library.
8 
9  KPGP is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software Foundation,
16  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #include "kpgpblock.h"
20 #include "kpgp.h"
21 
22 #include <QString>
23 #include <QByteArray>
24 
25 namespace Kpgp {
26 
27 Block::Block( const QByteArray& str )
28  : mText(str), mProcessedText(), mError(),
29  mSignatureUserId(), mSignatureKeyId(), mSignatureDate(),
30  mRequiredKey(), mEncryptedFor(),
31  mStatus(0), mHasBeenProcessed(false), mType(NoPgpBlock)
32 {
33 }
34 
35 Block::~Block()
36 {
37 }
38 
39 void
40 Block::reset()
41 {
42  mProcessedText = QByteArray();
43  mError = QByteArray();
44  mSignatureUserId.clear();
45  mSignatureKeyId = QByteArray();
46  mSignatureDate = QByteArray();
47  mRequiredKey = QByteArray();
48  mEncryptedFor.clear();
49  mStatus = 0;
50  mHasBeenProcessed = false;
51 }
52 
53 void
54 Block::clear()
55 {
56  reset();
57  mText = QByteArray();
58  mType = NoPgpBlock;
59 }
60 
61 BlockType
62 Block::determineType() const
63 {
64  if( !strncmp( mText.data(), "-----BEGIN PGP ", 15 ) )
65  {
66  if( !strncmp( mText.data() + 15, "SIGNED", 6 ) )
67  return ClearsignedBlock;
68  else if( !strncmp( mText.data() + 15, "SIGNATURE", 9 ) )
69  return SignatureBlock;
70  else if( !strncmp( mText.data() + 15, "PUBLIC", 6 ) )
71  return PublicKeyBlock;
72  else if( !strncmp( mText.data() + 15, "PRIVATE", 7 ) ||
73  !strncmp( mText.data() + 15, "SECRET", 6 ) )
74  return PrivateKeyBlock;
75  else if( !strncmp( mText.data() + 15, "MESSAGE", 7 ) )
76  {
77  if( !strncmp( mText.data() + 22, ", PART", 6 ) )
78  return MultiPgpMessageBlock;
79  else
80  return PgpMessageBlock;
81  }
82  else if( !strncmp( mText.data() + 15, "ARMORED FILE", 12 ) )
83  return PgpMessageBlock;
84  else
85  return UnknownBlock;
86  }
87  else
88  return NoPgpBlock;
89 }
90 
91 bool
92 Block::decrypt()
93 {
94  Kpgp::Module *pgp = Kpgp::Module::getKpgp();
95 
96  if( pgp == 0 )
97  return false;
98 
99  return pgp->decrypt( *this );
100 }
101 
102 bool
103 Block::verify()
104 {
105  Kpgp::Module *pgp = Kpgp::Module::getKpgp();
106 
107  if( pgp == 0 )
108  return false;
109 
110  return pgp->verify( *this );
111 }
112 
113 Kpgp::Result
114 Block::clearsign( const QByteArray& keyId, const QByteArray& charset )
115 {
116  Kpgp::Module *pgp = Kpgp::Module::getKpgp();
117 
118  if( pgp == 0 )
119  return Kpgp::Failure;
120 
121  return pgp->clearsign( *this, keyId, charset );
122 }
123 
124 Kpgp::Result
125 Block::encrypt( const QStringList& receivers, const QByteArray& keyId,
126  const bool sign, const QByteArray& charset )
127 {
128  Kpgp::Module *pgp = Kpgp::Module::getKpgp();
129 
130  if( pgp == 0 )
131  return Kpgp::Failure;
132 
133  return pgp->encrypt( *this, receivers, keyId, sign, charset );
134 }
135 
136 } // namespace Kpgp
Kpgp::Block::decrypt
bool decrypt()
decrypts this OpenPGP block if the passphrase is good.
Definition: kpgpblock.cpp:92
QList::clear
void clear()
QByteArray
Kpgp::SignatureBlock
Definition: kpgpblock.h:39
Kpgp::Module::encrypt
Kpgp::Result encrypt(Block &block, const QStringList &receivers, const KeyID &keyId, bool sign, const QByteArray &charset=0)
encrypts the given OpenPGP block for a list of persons.
Definition: kpgp.cpp:334
Kpgp::PrivateKeyBlock
Definition: kpgpblock.h:42
Kpgp::Module::getKpgp
static Kpgp::Module * getKpgp()
return the actual pgp object
Definition: kpgp.cpp:1067
QString::clear
void clear()
Kpgp::Block::~Block
~Block()
Definition: kpgpblock.cpp:35
Kpgp::Module
Definition: kpgp.h:75
Kpgp::MultiPgpMessageBlock
Definition: kpgpblock.h:38
Kpgp::BlockType
BlockType
Definition: kpgpblock.h:34
Kpgp::NoPgpBlock
Definition: kpgpblock.h:36
Kpgp::PublicKeyBlock
Definition: kpgpblock.h:41
QStringList
Kpgp::Module::clearsign
Kpgp::Result clearsign(Block &block, const KeyID &keyId, const QByteArray &charset=0)
clearsigns the given OpenPGP block with the key corresponding to the given key id.
Definition: kpgp.cpp:327
Kpgp::Block::reset
void reset()
Resets all information about this OpenPGP block.
Definition: kpgpblock.cpp:40
Kpgp::Failure
Definition: kpgp.h:67
Kpgp::Module::verify
bool verify(Block &block)
Tries to verify the given OpenPGP block.
Definition: kpgp.cpp:262
kpgpblock.h
Kpgp::Block::verify
bool verify()
tries to verify this (clearsigned) OpenPGP block
Definition: kpgpblock.cpp:103
Kpgp::Result
Result
Definition: kpgp.h:65
Kpgp::Block::clearsign
Kpgp::Result clearsign(const QByteArray &keyId, const QByteArray &charset=QByteArray())
clearsigns this OpenPGP block with the key corresponding to the given key id.
Definition: kpgpblock.cpp:114
Kpgp::PgpMessageBlock
Definition: kpgpblock.h:37
Kpgp::Block::encrypt
Kpgp::Result encrypt(const QStringList &receivers, const QByteArray &keyId, const bool sign, const QByteArray &charset=QByteArray())
encrypts this OpenPGP block for a list of persons.
Definition: kpgpblock.cpp:125
QByteArray::data
char * data()
Kpgp::Block::Block
Block(const QByteArray &str=QByteArray())
Definition: kpgpblock.cpp:27
Kpgp::ClearsignedBlock
Definition: kpgpblock.h:40
kpgp.h
Kpgp::UnknownBlock
Definition: kpgpblock.h:35
Kpgp::Module::decrypt
bool decrypt(Block &block)
decrypts the given OpenPGP block if the passphrase is good.
Definition: kpgp.cpp:283
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkpgp

Skip menu "libkpgp"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal