void tr_cryptoConstruct (tr_crypto * crypto, const uint8_t * torrentHash, bool isIncoming) { memset (crypto, 0, sizeof (tr_crypto)); crypto->isIncoming = isIncoming; tr_cryptoSetTorrentHash (crypto, torrentHash); }
void tr_peerIoSetTorrentHash( tr_peerIo * io, const uint8_t * hash ) { assert( tr_isPeerIo( io ) ); tr_cryptoSetTorrentHash( io->crypto, hash ); }
static int test_torrent_hash (void) { tr_crypto a; uint8_t hash[SHA_DIGEST_LENGTH]; int i; for (i = 0; i < SHA_DIGEST_LENGTH; ++i) hash[i] = i; tr_cryptoConstruct (&a, NULL, true); check (!tr_cryptoHasTorrentHash (&a)); check (tr_cryptoGetTorrentHash (&a) == NULL); tr_cryptoSetTorrentHash (&a, hash); check (tr_cryptoHasTorrentHash (&a)); check (tr_cryptoGetTorrentHash (&a) != NULL); check (memcmp (tr_cryptoGetTorrentHash (&a), hash, SHA_DIGEST_LENGTH) == 0); tr_cryptoDestruct (&a); for (i = 0; i < SHA_DIGEST_LENGTH; ++i) hash[i] = i + 1; tr_cryptoConstruct (&a, hash, false); check (tr_cryptoHasTorrentHash (&a)); check (tr_cryptoGetTorrentHash (&a) != NULL); check (memcmp (tr_cryptoGetTorrentHash (&a), hash, SHA_DIGEST_LENGTH) == 0); tr_cryptoSetTorrentHash (&a, NULL); check (!tr_cryptoHasTorrentHash (&a)); check (tr_cryptoGetTorrentHash (&a) == NULL); tr_cryptoDestruct (&a); return 0; }
tr_crypto * tr_cryptoNew( const uint8_t * torrentHash, int isIncoming ) { tr_crypto * crypto; crypto = tr_new0( tr_crypto, 1 ); crypto->isIncoming = isIncoming ? 1 : 0; tr_cryptoSetTorrentHash( crypto, torrentHash ); crypto->dh = NULL; return crypto; }