RetroShare/libretroshare/src/crypto/hashstream.h
Gioacchino Mazzurco 7642216912
Safer rsids API
Deprecate unsafe costructor, substituted by fromBufferUnsafe which explicitely
  marked suggest the caller to pay attention.
Use enum class for id types instead of constants
Make size constants more private
Use internal Id_t alias to avoid huge template lines
Remove and deprecate oguly names in favor of consistent names
2019-05-02 09:55:53 +02:00

60 lines
2.5 KiB
C++

/*******************************************************************************
* libretroshare/src/crypto: hashstream.h *
* *
* libretroshare: retroshare core library *
* *
* Copyright 2018 by Retroshare Team <retroshare.project@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#pragma once
#include <openssl/evp.h>
#include <util/rsdir.h>
namespace librs
{
namespace crypto
{
// Forward declare the class
class HashStream;
// Forward declare the template operator
template<class T> HashStream& operator<<(HashStream& u, const T&);
class HashStream
{
public:
enum HashType { UNKNOWN = 0x00,
SHA1 = 0x01
};
HashStream(HashType t);
~HashStream();
Sha1CheckSum hash() ;
template<class T> friend HashStream& operator<<(HashStream& u, const T&) ;
template<uint32_t ID_SIZE_IN_BYTES, bool UPPER_CASE, RsGenericIdType UNIQUE_IDENTIFIER>
friend HashStream& operator<<(HashStream& u, const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& r)
{
EVP_DigestUpdate(u.mdctx, r.toByteArray(), ID_SIZE_IN_BYTES);
return u;
}
private:
EVP_MD_CTX *mdctx ;
};
}
}