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

65 lines
1.9 KiB

  1. /* Copyright (C) 2014 eperi GmbH. All Rights Reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  12. /******************************************************************//**
  13. @file KeySingleton.cc
  14. Implementation of single pattern to keep keys for encrypting/decrypting pages.
  15. Created 09/13/2014
  16. ***********************************************************************/
  17. #include "KeySingleton.h"
  18. #include <stdlib.h>
  19. bool KeySingleton::instanceInited = false;
  20. KeySingleton KeySingleton::theInstance;
  21. EncKeys KeySingleton::encKeys;
  22. KeySingleton & KeySingleton::getInstance() {
  23. #ifdef UNIV_DEBUG
  24. if( !instanceInited) {
  25. fprintf(stderr, "Encryption / decryption keys were not initialized. "
  26. "You can not read encrypted tables or columns\n");
  27. }
  28. #endif UNIV_DEBUG
  29. return theInstance;
  30. }
  31. KeySingleton & KeySingleton::getInstance(const char *name, const char *url,
  32. const int initType, const char *filekey) {
  33. if(instanceInited) return theInstance;
  34. instanceInited = encKeys.initKeys(name, url, initType, filekey);
  35. if( !instanceInited) {
  36. fprintf(stderr, "Could not initialize any of the encryption / decryption keys. "
  37. "You can not read encrypted tables\n\n");
  38. fflush(stderr);
  39. }
  40. return theInstance;
  41. }
  42. keyentry *KeySingleton::getKeys(int id) {
  43. return encKeys.getKeys(id);
  44. }
  45. ibool KeySingleton::hasKey(int id) {
  46. return encKeys.getKeys(id) != NULL;
  47. }