reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

hash.hpp (1496B)


      1 /* ReaPack: Package manager for REAPER
      2  * Copyright (C) 2015-2025  Christian Fillion
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU Lesser General Public License as published by
      6  * the Free Software Foundation, either version 3 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  * GNU Lesser General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Lesser General Public License
     15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16  */
     17 
     18 #ifndef REAPACK_HASH_HPP
     19 #define REAPACK_HASH_HPP
     20 
     21 #include <memory>
     22 #include <string>
     23 
     24 class Hash {
     25 public:
     26   enum Algorithm {
     27     SHA256 = 0x12,
     28   };
     29 
     30   static bool getAlgorithm(const std::string &hash, Algorithm *out);
     31 
     32   Hash(Algorithm);
     33   Hash(const Hash &) = delete;
     34 
     35   void addData(const char *data, size_t len);
     36   const std::string &digest();
     37 
     38 private:
     39   class Context {
     40   public:
     41     virtual ~Context() = default;
     42     virtual size_t hashSize() const = 0;
     43     virtual void addData(const char *data, size_t len) = 0;
     44     virtual void getHash(unsigned char *out) = 0;
     45   };
     46 
     47   class CNGContext;
     48   class SHA256Context;
     49   class EVPContext;
     50 
     51   Algorithm m_algo;
     52   std::string m_value;
     53   std::unique_ptr<Context> m_context;
     54 };
     55 
     56 #endif