本文整理汇总了C++中SHA类的典型用法代码示例。如果您正苦于以下问题:C++ SHA类的具体用法?C++ SHA怎么用?C++ SHA使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SHA类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: sha_test
int sha_test()
{
SHA sha;
byte hash[SHA::DIGEST_SIZE];
testVector test_sha[] =
{
testVector("abc",
"\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
"\x6C\x9C\xD0\xD8\x9D"),
testVector("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29"
"\xE5\xE5\x46\x70\xF1"),
testVector("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaa",
"\x00\x98\xBA\x82\x4B\x5C\x16\x42\x7B\xD7\xA1\x12\x2A\x5A\x44"
"\x2A\x25\xEC\x64\x4D"),
testVector("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaa",
"\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
"\x53\x99\x5E\x26\xA0")
};
int times( sizeof(test_sha) / sizeof(testVector) );
for (int i = 0; i < times; ++i) {
sha.Update(test_sha[i].input_, test_sha[i].inLen_);
sha.Final(hash);
if (memcmp(hash, test_sha[i].output_, SHA::DIGEST_SIZE) != 0)
return -1 - i;
}
return 0;
}
开发者ID:0x-ff,项目名称:libmysql-android,代码行数:35,代码来源:test.cpp
示例2: switch
bool UniqueMUCRoom::handleIqID( Stanza *stanza, int context )
{
switch( stanza->subtype() )
{
case StanzaIqResult:
if( context == RequestUniqueName )
{
Tag *u = stanza->findChild( "unique", XMLNS_MUC_UNIQUE );
if( u )
{
const std::string& name = u->cdata();
if( !name.empty() )
setName( name );
}
}
break;
case StanzaIqError:
if( context == RequestUniqueName )
{
SHA s;
s.feed( m_parent->jid().full() );
s.feed( m_parent->getID() );
setName( s.hex() );
}
break;
default:
break;
}
MUCRoom::join();
return false;
}
开发者ID:SupportSpace,项目名称:SupportCenter,代码行数:33,代码来源:uniquemucroom.cpp
示例3: assert
bool DSA::GeneratePrimes(const byte *seedIn, unsigned int g, int &counter,
Integer &p, unsigned int L, Integer &q, bool useInputCounterValue)
{
assert(g%8 == 0);
SHA sha;
SecByteBlock seed(seedIn, g/8);
SecByteBlock U(SHA::DIGESTSIZE);
SecByteBlock temp(SHA::DIGESTSIZE);
SecByteBlock W(((L-1)/160+1) * SHA::DIGESTSIZE);
const int n = (L-1) / 160;
const int b = (L-1) % 160;
Integer X;
sha.CalculateDigest(U, seed, g/8);
for (int i=g/8-1, carry=true; i>=0 && carry; i--)
carry=!++seed[i];
sha.CalculateDigest(temp, seed, g/8);
xorbuf(U, temp, SHA::DIGESTSIZE);
U[0] |= 0x80;
U[SHA::DIGESTSIZE-1] |= 1;
q.Decode(U, SHA::DIGESTSIZE);
if (!IsPrime(q))
return false;
int counterEnd = useInputCounterValue ? counter+1 : 4096;
for (int c = 0; c < counterEnd; c++)
{
for (int k=0; k<=n; k++)
{
for (int i=g/8-1, carry=true; i>=0 && carry; i--)
carry=!++seed[i];
if (!useInputCounterValue || c == counter)
sha.CalculateDigest(W+(n-k)*SHA::DIGESTSIZE, seed, g/8);
}
if (!useInputCounterValue || c == counter)
{
W[SHA::DIGESTSIZE - 1 - b/8] |= 0x80;
X.Decode(W + SHA::DIGESTSIZE - 1 - b/8, L/8);
p = X-((X % (2*q))-1);
if (p.GetBit(L-1) && IsPrime(p))
{
counter = c;
return true;
}
}
}
return false;
}
开发者ID:acat,项目名称:emule,代码行数:55,代码来源:dsa.cpp
示例4: Tag
bool SOCKS5BytestreamManager::requestSOCKS5Bytestream( const JID& to, S5BMode /*mode*/,
const std::string& sid )
{
if( !m_parent )
return false;
if( m_hosts.empty() )
{
m_parent->logInstance().log( LogLevelWarning, LogAreaClassS5BManager,
"No stream hosts set, cannot request bytestream." );
return false;
}
const std::string& msid = sid.empty() ? m_parent->getID() : sid;
const std::string& id = m_parent->getID();
Tag *iq = new Tag( "iq" );
iq->addAttribute( "type", "set" );
iq->addAttribute( "to", to.full() );
iq->addAttribute( "id", id );
Tag *q = new Tag( iq, "query", "xmlns", XMLNS_BYTESTREAMS );
q->addAttribute( "sid", msid );
q->addAttribute( "mode", /*( mode == S5BTCP ) ?*/ "tcp" /*: "udp"*/ );
StreamHostList::const_iterator it = m_hosts.begin();
for( ; it != m_hosts.end(); ++it )
{
Tag* s = new Tag( q, "streamhost", "jid", (*it).jid.full() );
s->addAttribute( "host", (*it).host );
s->addAttribute( "port", (*it).port );
}
if( m_server )
{
SHA sha;
sha.feed( msid );
sha.feed( m_parent->jid().full() );
sha.feed( to.full() );
m_server->registerHash( sha.hex() );
}
AsyncS5BItem asi;
asi.sHosts = m_hosts;
asi.id = id;
asi.from = to;
asi.incoming = false;
m_asyncTrackMap[msid] = asi;
m_trackMap[id] = msid;
m_parent->trackID( this, id, S5BOpenStream );
m_parent->send( iq );
return true;
}
开发者ID:wuyingfengsui,项目名称:V6Chat,代码行数:53,代码来源:socks5bytestreammanager.cpp
示例5: generate
const std::string Capabilities::ver() const
{
if( !m_disco )
return m_ver;
SHA sha;
sha.feed( generate( m_disco->identities(), m_disco->features( true ), m_disco->form() ) );
const std::string& hash = Base64::encode64( sha.binary() );
m_disco->removeNodeHandlers( const_cast<Capabilities*>( this ) );
m_disco->registerNodeHandler( const_cast<Capabilities*>( this ), m_node + '#' + hash );
return hash;
}
开发者ID:Barrett17,项目名称:Caya,代码行数:12,代码来源:capabilities.cpp
示例6:
void SOCKS5Bytestream::setConnectionImpl( ConnectionBase* connection )
{
if( m_socks5 )
delete m_socks5; // deletes m_connection as well
m_connection = connection;
SHA sha;
sha.feed( m_sid );
sha.feed( m_initiator.full() );
sha.feed( m_target.full() );
m_socks5 = new ConnectionSOCKS5Proxy( this, connection, m_logInstance, sha.hex(), 0 );
}
开发者ID:crazyit,项目名称:iGame,代码行数:13,代码来源:socks5bytestream.cpp
示例7: data
void jAccount::s_saveVCard(VCard *vcard)
{
QString hex = "";
const VCard::Photo &photo = vcard->photo();
if(!photo.binval.empty())
{
QByteArray data(photo.binval.c_str(),photo.binval.length());
SHA sha;
sha.feed(photo.binval);
sha.finalize();
hex = jProtocol::fromStd(sha.hex());
}
m_jabber_protocol->updateAvatarPresence(hex);
m_jabber_protocol->storeVCard(vcard);
}
开发者ID:RankoR,项目名称:mqutim,代码行数:15,代码来源:jAccount.cpp
示例8: Query
NonSaslAuth::Query* NonSaslAuth::Query::newInstance( const std::string& user,
const std::string& sid,
const std::string& pwd,
const std::string& resource ) const
{
Query* q = new Query( user );
if( m_digest && !sid.empty() )
{
SHA sha;
sha.feed( sid );
sha.feed( pwd );
q->m_pwd = sha.hex();
}
else
q->m_pwd = pwd;
q->m_resource = resource;
q->m_digest = m_digest;
return q;
}
开发者ID:iVideo,项目名称:weishao,代码行数:20,代码来源:nonsaslauth.cpp
示例9: dsa_test
int dsa_test()
{
Source source;
FileSource("../certs/dsa512.der", source);
if (source.size() == 0) {
FileSource("../../certs/dsa512.der", source); // for testsuite
if (source.size() == 0) {
FileSource("../../../certs/dsa512.der", source); // win32 Debug dir
if (source.size() == 0)
err_sys("where's your certs dir?", -89);
}
}
const char msg[] = "this is the message";
byte signature[40];
DSA_PrivateKey priv(source);
DSA_Signer signer(priv);
SHA sha;
byte digest[SHA::DIGEST_SIZE];
sha.Update((byte*)msg, sizeof(msg));
sha.Final(digest);
signer.Sign(digest, signature, rng);
byte encoded[sizeof(signature) + 6];
byte decoded[40];
word32 encSz = EncodeDSA_Signature(signer.GetR(), signer.GetS(), encoded);
DecodeDSA_Signature(decoded, encoded, encSz);
DSA_PublicKey pub(priv);
DSA_Verifier verifier(pub);
if (!verifier.Verify(digest, decoded))
return -90;
return 0;
}
开发者ID:0x-ff,项目名称:libmysql-android,代码行数:40,代码来源:test.cpp
示例10: parent
bool SOCKS5BytestreamManager::requestSOCKS5Bytestream( const JID& to, S5BMode mode,
const std::string& sid,
const JID& from )
{
if( !m_parent )
{
m_parent->logInstance().warn( LogAreaClassS5BManager,
"No parent (ClientBase) set, cannot request bytestream." );
return false;
}
if( m_hosts.empty() )
{
m_parent->logInstance().warn( LogAreaClassS5BManager,
"No stream hosts set, cannot request bytestream." );
return false;
}
const std::string& msid = sid.empty() ? m_parent->getID() : sid;
const std::string& id = m_parent->getID();
IQ iq( IQ::Set, to, id );
iq.addExtension( new Query( msid, mode, m_hosts ) );
if( from )
iq.setFrom( from );
if( m_server )
{
SHA sha;
sha.feed( msid );
if( from )
sha.feed( from.full() );
else
sha.feed( m_parent->jid().full() );
sha.feed( to.full() );
m_server->registerHash( sha.hex() );
}
AsyncS5BItem asi;
asi.sHosts = m_hosts;
asi.id = id;
asi.from = to;
asi.to = from ? from : m_parent->jid();
asi.incoming = false;
m_asyncTrackMap[msid] = asi;
m_trackMap[id] = msid;
m_parent->send( iq, this, S5BOpenStream );
return true;
}
开发者ID:kofbashen,项目名称:weishao,代码行数:50,代码来源:socks5bytestreammanager.cpp
示例11: swap
inline void swap(SHA& a, SHA& b)
{
a.Swap(b);
}
开发者ID:Aitaobao,项目名称:mysql,代码行数:4,代码来源:sha.hpp
示例12: GetName
// process NAME, either issuer or subject
void CertDecoder::GetName(NameType nt)
{
if (source_.GetError().What()) return;
SHA sha;
word32 length = GetSequence(); // length of all distinguished names
if (length >= ASN_NAME_MAX)
goto err;
length += source_.get_index();
char *ptr, *buf_end;
if (nt == ISSUER) {
ptr= issuer_;
buf_end= ptr + sizeof(issuer_) - 1; // 1 byte for trailing 0
}
else {
ptr= subject_;
buf_end= ptr + sizeof(subject_) - 1; // 1 byte for trailing 0
}
while (source_.get_index() < length) {
GetSet();
GetSequence();
byte b = source_.next();
if (b != OBJECT_IDENTIFIER) {
source_.SetError(OBJECT_ID_E);
return;
}
word32 oidSz = GetLength(source_);
byte joint[2];
memcpy(joint, source_.get_current(), sizeof(joint));
// v1 name types
if (joint[0] == 0x55 && joint[1] == 0x04) {
source_.advance(2);
byte id = source_.next();
b = source_.next(); // strType
word32 strLen = GetLength(source_);
switch (id) {
case COMMON_NAME:
if (!(ptr= AddTag(ptr, buf_end, "/CN=", 4, strLen)))
goto err;
break;
case SUR_NAME:
if (!(ptr= AddTag(ptr, buf_end, "/SN=", 4, strLen)))
goto err;
break;
case COUNTRY_NAME:
if (!(ptr= AddTag(ptr, buf_end, "/C=", 3, strLen)))
goto err;
break;
case LOCALITY_NAME:
if (!(ptr= AddTag(ptr, buf_end, "/L=", 3, strLen)))
goto err;
break;
case STATE_NAME:
if (!(ptr= AddTag(ptr, buf_end, "/ST=", 4, strLen)))
goto err;
break;
case ORG_NAME:
if (!(ptr= AddTag(ptr, buf_end, "/O=", 3, strLen)))
goto err;
break;
case ORGUNIT_NAME:
if (!(ptr= AddTag(ptr, buf_end, "/OU=", 4, strLen)))
goto err;
break;
}
sha.Update(source_.get_current(), strLen);
source_.advance(strLen);
}
else {
bool email = false;
if (joint[0] == 0x2a && joint[1] == 0x86) // email id hdr
email = true;
source_.advance(oidSz + 1);
word32 length = GetLength(source_);
if (email && !(ptr= AddTag(ptr, buf_end, "/emailAddress=", 14, length)))
goto err;
source_.advance(length);
}
}
*ptr= 0;
sha.Final(nt == ISSUER ? issuerHash_ : subjectHash_);
return;
err:
source_.SetError(CONTENT_E);
//.........这里部分代码省略.........
开发者ID:zhongliangkang,项目名称:mysql-5.6.6-labs-april-2012-sky,代码行数:101,代码来源:asn.cpp
示例13: TEST
TEST(SHATest, sha256Text_a_1m) {
SHA sha;
std::string hash = sha.sha256(boost::filesystem::path("src/test/hash/a_1m.dat"));
ASSERT_EQ("cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0",hash);
}
开发者ID:dozedoff,项目名称:commoncpp,代码行数:5,代码来源:SHATest.cpp
示例14: re
void NonSaslAuthTest::send( const IQ& iq, IqHandler* ih, int ctx )
{
if( m_test == 1 )
{
const NonSaslAuth::Query* q = iq.findExtension<NonSaslAuth::Query>( ExtNonSaslAuth );
if( q )
{
m_result++;
m_test = 2;
IQ re( IQ::Result, iq.from(), iq.id() );
Tag* d = new Tag( "query" );
d->setXmlns( XMLNS_AUTH );
new Tag( d, "username" );
new Tag( d, "password" );
new Tag( d, "resource" );
re.addExtension( new NonSaslAuth::Query( d ) );
ih->handleIqID( re, ctx );
delete d;
}
}
else if( m_test == 2 )
{
const NonSaslAuth::Query* q = iq.findExtension<NonSaslAuth::Query>( ExtNonSaslAuth );
if( q )
{
Tag* d = q->tag();
if( d->xml() == "<query xmlns='" + XMLNS_AUTH + "'>"
"<username>user</username>"
"<password>pwd</password>"
"<resource>resource</resource>"
"</query>" )
{
m_result++;
IQ re( IQ::Result, iq.from(), iq.id() );
ih->handleIqID( re, ctx );
}
delete d;
}
}
else if( m_test == 3 )
{
const NonSaslAuth::Query* q = iq.findExtension<NonSaslAuth::Query>( ExtNonSaslAuth );
if( q )
{
m_result++;
m_test = 4;
IQ re( IQ::Result, iq.from(), iq.id() );
Tag* d = new Tag( "query" );
d->setXmlns( XMLNS_AUTH );
new Tag( d, "username" );
new Tag( d, "digest" );
new Tag( d, "password" );
new Tag( d, "resource" );
re.addExtension( new NonSaslAuth::Query( d ) );
ih->handleIqID( re, ctx );
delete d;
}
}
else if( m_test == 4 )
{
const NonSaslAuth::Query* q = iq.findExtension<NonSaslAuth::Query>( ExtNonSaslAuth );
if( q )
{
Tag* d = q->tag();
SHA sha;
sha.feed( "sid2" );
sha.feed( "pwd" );
if( d->xml() == "<query xmlns='" + XMLNS_AUTH + "'>"
"<username>user</username>"
"<digest>" + sha.hex() + "</digest>"
"<resource>resource</resource>"
"</query>" )
{
m_result += 2;
IQ re( IQ::Result, iq.from(), iq.id() );
ih->handleIqID( re, ctx );
}
delete d;
}
}
}
开发者ID:github188,项目名称:BasicFunctionCodeBase,代码行数:81,代码来源:nonsaslauth_test.cpp
示例15: switch
bool NonSaslAuth::handleIqID( Stanza *stanza, int context )
{
switch( stanza->subtype() )
{
case StanzaIqError:
{
m_parent->setAuthed( false );
m_parent->disconnect( ConnAuthenticationFailed );
Tag *t = stanza->findChild( "error" );
if( t )
{
if( t->hasChild( "conflict" ) || t->hasAttribute( "code", "409" ) )
m_parent->setAuthFailure( NonSaslConflict );
else if( t->hasChild( "not-acceptable" ) || t->hasAttribute( "code", "406" ) )
m_parent->setAuthFailure( NonSaslNotAcceptable );
else if( t->hasChild( "not-authorized" ) || t->hasAttribute( "code", "401" ) )
m_parent->setAuthFailure( NonSaslNotAuthorized );
}
break;
}
case StanzaIqResult:
switch( context )
{
case TRACK_REQUEST_AUTH_FIELDS:
{
const std::string& id = m_parent->getID();
Tag *iq = new Tag( "iq" );
iq->addAttribute( "id", id );
iq->addAttribute( "type", "set" );
Tag *query = new Tag( iq, "query" );
query->addAttribute( "xmlns", XMLNS_AUTH );
new Tag( query, "username", m_parent->jid().username() );
new Tag( query, "resource", m_parent->jid().resource() );
Tag *q = stanza->findChild( "query" );
if( ( q->hasChild( "digest" ) ) && !m_sid.empty() )
{
SHA sha;
sha.feed( m_sid );
sha.feed( m_parent->password() );
sha.finalize();
new Tag( query, "digest", sha.hex() );
}
else
{
new Tag( query, "password", m_parent->password() );
}
m_parent->trackID( this, id, TRACK_SEND_AUTH );
m_parent->send( iq );
break;
}
case TRACK_SEND_AUTH:
m_parent->setAuthed( true );
m_parent->connected();
break;
}
break;
default:
break;
}
return false;
}
开发者ID:soubok,项目名称:libset,代码行数:66,代码来源:nonsaslauth.cpp
示例16: switch
bool SOCKS5BytestreamManager::handleIqID( Stanza *stanza, int context )
{
StringMap::iterator it = m_trackMap.find( stanza->id() );
if( it == m_trackMap.end() )
return false;
switch( context )
{
case S5BOpenStream:
{
switch( stanza->subtype() )
{
case StanzaIqResult:
{
Tag* q = stanza->findChild( "query", "xmlns", XMLNS_BYTESTREAMS );
if( !q || !m_socks5BytestreamHandler )
return false;
Tag* s = q->findChild( "streamhost-used" );
if( !s || !s->hasAttribute( "jid" ) )
return false;
const std::string & proxy = s->findAttribute( "jid" );
const StreamHost* sh = findProxy( stanza->from(), proxy, (*it).second );
if( sh )
{
SOCKS5Bytestream* s5b = 0;
bool selfProxy = ( proxy == m_parent->jid().full() && m_server );
if( selfProxy )
{
SHA sha;
sha.feed( (*it).second );
sha.feed( m_parent->jid().full() );
sha.feed( stanza->from().full() );
s5b = new SOCKS5Bytestream( this, m_server->getConnection( sha.hex() ),
m_parent->logInstance(),
m_parent->jid(), stanza->from(),
(*it).second );
}
else
{
s5b = new SOCKS5Bytestream( this, m_parent->connectionImpl()->newInstance(),
m_parent->logInstance(),
m_parent->jid(), stanza->from(),
(*it).second );
StreamHostList shl;
shl.push_back( *sh );
s5b->setStreamHosts( shl );
}
m_s5bMap[(*it).second] = s5b;
m_socks5BytestreamHandler->handleOutgoingSOCKS5Bytestream( s5b );
if( selfProxy )
s5b->activate();
}
break;
}
case StanzaIqError:
m_socks5BytestreamHandler->handleSOCKS5BytestreamError( stanza, (*it).second );
break;
default:
break;
}
break;
}
case S5BActivateStream:
{
switch( stanza->subtype() )
{
case StanzaIqResult:
{
S5BMap::const_iterator it5 = m_s5bMap.find( (*it).second );
if( it5 != m_s5bMap.end() )
(*it5).second->activate();
break;
}
case StanzaIqError:
m_socks5BytestreamHandler->handleSOCKS5BytestreamError( stanza, (*it).second );
break;
default:
break;
}
break;
}
default:
break;
}
m_trackMap.erase( it );
return false;
}
开发者ID:wuyingfengsui,项目名称:V6Chat,代码行数:90,代码来源:socks5bytestreammanager.cpp
示例17: main_test1
int main_test1( int /*argc*/, char** /*argv*/ )
{
int fail = 0;
std::string name;
Tag* t = 0;
// -------
{
name = "field request";
NonSaslAuth::Query q( "user" );
t = q.tag();
if( !t || t->xml() != "<query xmlns='" + XMLNS_AUTH + "'>"
"<username>user</username></query>" )
{
++fail;
fprintf( stderr, "test '%s' failed\n", name.c_str() );
}
delete t;
t = 0;
}
// -------
{
name = "reply w/ pwd";
Tag* q = new Tag( "query" );
q->setXmlns( XMLNS_AUTH );
new Tag( q, "username" );
new Tag( q, "password" );
new Tag( q, "resource" );
NonSaslAuth::Query n( q );
NonSaslAuth::Query* nq = n.newInstance( "user", "sid", "pwd", "resource" );
t = nq->tag();
if( !t || t->xml() != "<query xmlns='" + XMLNS_AUTH + "'>"
"<username>user</username>"
"<password>pwd</password>"
"<resource>resource</resource>"
"</query>" )
{
++fail;
fprintf( stderr, "test '%s' failed\n", name.c_str() );
}
delete nq;
delete q;
delete t;
t = 0;
}
// -------
{
name = "reply w/ digest";
Tag* q = new Tag( "query" );
q->setXmlns( XMLNS_AUTH );
new Tag( q, "username" );
new Tag( q, "password" );
new Tag( q, "digest" );
new Tag( q, "resource" );
NonSaslAuth::Query n( q );
NonSaslAuth::Query* nq = n.newInstance( "user", "sid", "pwd", "resource" );
SHA sha;
sha.feed( "sid" );
sha.feed( "pwd" );
t = nq->tag();
if( !t || t->xml() != "<query xmlns='" + XMLNS_AUTH + "'>"
"<username>user</username>"
"<digest>" + sha.hex() + "</digest>"
"<resource>resource</resource>"
"</query>" )
{
++fail;
fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
}
delete nq;
delete q;
delete t;
t = 0;
}
// -------
{
StanzaExtensionFactory sef;
sef.registerExtension( new NonSaslAuth::Query() );
name = "NonSaslAuth::Query/SEFactory test";
Tag* f = new Tag( "iq" );
new Tag( f, "query", "xmlns", XMLNS_AUTH );
IQ iq( IQ::Set, JID(), "" );
sef.addExtensions( iq, f );
const NonSaslAuth::Query* se = iq.findExtension<NonSaslAuth::Query>( ExtNonSaslAuth );
if( se == 0 )
{
++fail;
fprintf( stderr, "test '%s' failed\n", name.c_str() );
}
delete f;
}
if( fail == 0 )
{
printf( "NonSaslAuth::Query: OK\n" );
//.........这里部分代码省略.........
开发者ID:SiteView,项目名称:eccmeteor,代码行数:101,代码来源:nonsaslauthquery_test.cpp
示例18: switch
void SOCKS5BytestreamManager::handleIqID( const IQ& iq, int context )
{
StringMap::iterator it = m_trackMap.find( iq.id() );
if( it == m_trackMap.end() )
return;
switch( context )
{
case S5BOpenStream:
{
switch( iq.subtype() )
{
case IQ::Result:
{
const Query* q = iq.findExtension<Query>( ExtS5BQuery );
if( q && m_socks5BytestreamHandler )
{
const std::string& proxy = q->jid().full();
const StreamHost* sh = findProxy( iq.from(), proxy, (*it).second );
if( sh )
{
SOCKS5Bytestream* s5b = 0;
bool selfProxy = ( proxy == m_parent->jid().full() && m_server );
if( selfProxy )
{
SHA sha;
sha.feed( (*it).second );
sha.feed( iq.to().full() );
sha.feed( iq.from().full() );
s5b = new SOCKS5Bytestream( this, m_server->getConnection( sha.hex() ),
m_parent->logInstance(),
iq.to(), iq.from(),
(*it).second );
}
else
{
s5b = new SOCKS5Bytestream( this, m_parent->connectionImpl()->newInstance(),
m_parent->logInstance(),
iq.to(), iq.from(),
(*it).second );
s5b->setStreamHosts( StreamHostList( 1, *sh ) );
}
m_s5bMap[(*it).second] = s5b;
m_socks5BytestreamHandler->handleOutgoingBytestream( s5b );
if( selfProxy )
s5b->activate();
}
}
break;
}
case IQ::Error:
m_socks5BytestreamHandler->handleBytestreamError( iq, (*it).second );
break;
default:
break;
}
break;
}
case S5BActivateStream:
{
switch( iq.subtype() )
{
case IQ::Result:
{
S5BMap::const_iterator it5 = m_s5bMap.find( (*it).second );
if( it5 != m_s5bMap.end() )
(*it5).second->activate();
break;
}
case IQ::Error:
m_socks5BytestreamHandler->handleBytestreamError( iq, (*it).second );
break;
default:
break;
}
break;
}
default:
break;
}
m_trackMap.erase( it );
}
开发者ID:kofbashen,项目名称:weishao,代码行数:82,代码来源:socks5bytestreammanager.cpp
示例19: main
int main( int /*argc*/, char** /*argv*/ )
{
int fail = 0;
std::string name;
SHA sha;
// -------
name = "empty string";
sha.feed( "" );
sha.finalize();
if( sha.hex() != "da39a3ee5e6b4b0d3255bfef95601890afd80709" )
{
++fail;
fprintf( stderr, "test '%s' failed\n", name.c_str() );
}
sha.reset();
// -------
name = "The quick brown fox jumps over the lazy dog";
sha.feed( name );
sha.finalize();
if( sha.hex() != "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" )
{
++fail;
fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() );
}
sha.reset();
// -------
name = "The quick brown fox jumps over the lazy cog";
sha.feed( name );
sha.finalize();
if( sha.hex() != "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3" )
{
++fail;
fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() );
}
sha.reset();
// -------
name = "two-step";
sha.feed( "The quick brown fox " );
sha.feed( "jumps over the lazy dog" );
sha.finalize();
if( sha.hex() != "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" )
{
++fail;
fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() );
}
sha.reset();
// -------
name = "54byte string";
sha.feed( std::string( 54, 'x' ) );
sha.finalize();
if( sha.hex() != "31045e7bb077ff8d188a776b196b980388735dbb" )
{
++fail;
fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() );
}
sha.reset();
// -------
name = "55byte string";
sha.feed( std::string( 55, 'x' ) );
sha.finalize();
if( sha.hex() != "cef734ba81a024479e09eb5a75b6ddae62e6abf1" )
{
++fail;
fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() );
}
sha.reset();
// -------
name = "56byte string";
sha.feed( std::string( 56, 'x' ) );
sha.finalize();
if( sha.hex() != "901305367c259952f4e7af8323f480d59f81335b" )
{
++fail;
fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() );
}
sha.reset();
// -------
name = "57byte string";
sha.feed( std::string( 57, 'x' ) );
sha.finalize();
if( sha.hex() != "025ecbd5d70f8fb3c5457cd96bab13fda305dc59" )
{
++fail;
fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() );
}
sha.reset();
// -------
name = "many-step";
sha.feed( "The" );
//.........这里部分代码省略.........
开发者ID:PeterXu,项目名称:sipstack,代码行数:101,代码来源:sha_test.cpp
示例20: GetName
// process NAME, either issuer or subject
void CertDecoder::GetName(NameType nt)
{
if (source_.GetError().What()) return;
SHA sha;
word32 length = GetSequence(); // length of all distinguished names
if (length >= ASN_NAME_MAX)
return;
if (source_.IsLeft(length) == false) return;
length += source_.get_index();
char* ptr;
char* buf_end;
if (nt == ISSUER) {
ptr = issuer_;
buf_end = ptr + sizeof(issuer_) - 1; // 1 byte for trailing 0
}
else {
ptr = subject_;
buf_end = ptr + sizeof(subject_) - 1; // 1 byte for trailing 0
}
while (source_.get_index() < length) {
GetSet();
if (source_.GetError().What() == SET_E) {
source_.SetError(NO_ERROR_E); // extensions may only have sequence
source_.prev();
}
GetSequence();
byte b = source_.next();
if (b != OBJECT_IDENTIFIER) {
source_.SetError(OBJECT_ID_E);
return;
}
word32 oidSz = GetLength(source_);
if (source_.IsLeft(oidSz) == false) return;
byte joint[2];
if (source_.IsLeft(sizeof(joint)) == false) return;
memcpy(joint, source_.get_current(), sizeof(joint));
// v1 name types
if (joint[0] == 0x55 && joint[1] == 0x04) {
source_.advance(2);
byte id = source_.next();
b = source_.next(); // strType
word32 strLen = GetLength(source_);
if (source_.IsLeft(strLen) == false) return;
switch (id) {
case COMMON_NAME:
if (!(ptr = AddTag(ptr, buf_end, "/CN=", 4, strLen)))
return;
if (nt == ISSUER) {
issCnPos_ = (int)(ptr - strLen - issuer_);
issCnLen_ = (int)strLen;
} else {
subCnPos_ = (int)(ptr - strLen - subject_);
subCnLen_ = (int)strLen;
}
break;
case SUR_NAME:
if (!(ptr = AddTag(ptr, buf_end, "/SN=", 4, strLen)))
return;
break;
case COUNTRY_NAME:
if (!(ptr = AddTag(ptr, buf_end, "/C=", 3, strLen)))
return;
break;
case LOCALITY_NAME:
if (!(ptr = AddTag(ptr, buf_end, "/L=", 3, strLen)))
return;
break;
case STATE_NAME:
if (!(ptr = AddTag(ptr, buf_end, "/ST=", 4, strLen)))
return;
break;
case ORG_NAME:
if (!(ptr = AddTag(ptr, buf_end, "/O=", 3, strLen)))
return;
break;
case ORGUNIT_NAME:
if (!(ptr = AddTag(ptr, buf_end, "/OU=", 4, strLen)))
return;
break;
}
sha.Update(source_.get_current(), strLen);
source_.advance(strLen);
}
else {
bool email = false;
if (joint[0] == 0x2a && joint[1] == 0x86) // email id hdr
email = true;
//.........这里部分代码省略.........
开发者ID:asmlib,项目名称:mariadb-server,代码行数:101,代码来源:asn.cpp
注:本文中的SHA类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论