kleopatra
Go to the documentation of this file.
33 #include <config-kleopatra.h>
37 #include <kleo/exception.h>
46 static unsigned char unhex(
unsigned char ch ) {
47 if ( ch >=
'0' && ch <=
'9' )
49 if ( ch >=
'A' && ch <=
'F' )
51 if ( ch >=
'a' && ch <=
'f' )
54 throw Exception( gpg_error( GPG_ERR_ASS_SYNTAX ),
55 i18n(
"Invalid hex char '%1' in input stream.",
56 QString::fromLatin1( &cch, 1 ) ) );
61 result.reserve( in.size() );
62 for ( std::string::const_iterator it = in.begin(), end = in.end() ; it != end ; ++it )
65 unsigned char ch =
'\0';
67 throw Exception( gpg_error( GPG_ERR_ASS_SYNTAX ),
68 i18n(
"Premature end of hex-encoded char in input stream") );
69 ch |=
unhex( *it ) << 4;
72 throw Exception( gpg_error( GPG_ERR_ASS_SYNTAX ),
73 i18n(
"Premature end of hex-encoded char in input stream") );
75 result.push_back( ch );
76 }
else if ( *it ==
'+' ) {
79 result.push_back( *it );
86 result.reserve( 3 * in.size() );
88 static const char hex[] =
"0123456789ABCDEF";
90 for ( std::string::const_iterator it = in.begin(), end = in.end() ; it != end ; ++it )
91 switch (
const unsigned char ch = *it ) {
93 if ( ( ch >=
'!' && ch <=
'~' ) || ch > 0xA0 ) {
109 result += hex[ (ch & 0xF0) >> 4 ];
110 result += hex[ (ch & 0x0F) ];
133 return QByteArray( result.data(), result.size() );
140 return QByteArray( result.data(), result.size() );
std::string hexencode(const char *s)
static unsigned char unhex(unsigned char ch)
std::string hexdecode(const char *s)
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 by
doxygen 1.8.7 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.