You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

decrypt_base.h 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * \file src/decryption/decrypt_base.h
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #pragma once
  12. #include "lite/global.h"
  13. #include "misc.h"
  14. namespace lite {
  15. struct DecryptionStaticData {
  16. std::unordered_map<
  17. std::string,
  18. std::pair<DecryptionFunc, std::shared_ptr<std::vector<uint8_t>>>>
  19. decryption_methods;
  20. LITE_MUTEX map_mutex;
  21. };
  22. DecryptionStaticData& decryption_static_data();
  23. template <int count>
  24. struct DecryptionRegister;
  25. } // namespace lite
  26. #define CONCAT_IMPL(a, b) a##b
  27. #define MACRO_CONCAT(a, b) CONCAT_IMPL(a, b)
  28. #define REGIST_DECRYPTION_METHOD(name_, func_, key_) \
  29. REGIST_DECRYPTION_METHOD_WITH_NUM(__COUNTER__, name_, func_, key_)
  30. #define REGIST_DECRYPTION_METHOD_WITH_NUM(number_, name_, func_, key_) \
  31. template <> \
  32. struct DecryptionRegister<number_> { \
  33. DecryptionRegister() { register_decryption_and_key(name_, func_, key_); } \
  34. }; \
  35. namespace { \
  36. DecryptionRegister<number_> MACRO_CONCAT(decryption_, number_); \
  37. }
  38. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}