Source code of Windows XP (NT5)
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.

171 lines
4.3 KiB

  1. // ACont.cpp -- CAbstractContainer implementation
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #include "cciCont.h"
  8. #include "TransactionWrap.h"
  9. #include "cciCert.h"
  10. #include "cciKeyPair.h"
  11. #include "cciPriKey.h"
  12. #include "cciPubKey.h"
  13. using namespace std;
  14. using namespace cci;
  15. /////////////////////////// LOCAL/HELPER /////////////////////////////////
  16. namespace
  17. {
  18. void
  19. Clear(CKeyPair const &rkp)
  20. {
  21. CPublicKey pubKey(rkp->PublicKey());
  22. if (pubKey)
  23. pubKey->Delete();
  24. CPrivateKey priKey(rkp->PrivateKey());
  25. if (priKey)
  26. priKey->Delete();
  27. CCertificate cert(rkp->Certificate());
  28. if (cert)
  29. cert->Delete();
  30. }
  31. } // namespace
  32. /////////////////////////// PUBLIC /////////////////////////////////
  33. // Types
  34. // C'tors/D'tors
  35. CAbstractContainer::~CAbstractContainer()
  36. {}
  37. // Operators
  38. bool
  39. CAbstractContainer::operator==(CAbstractContainer const &rhs) const
  40. {
  41. CTransactionWrap wrap(m_hcard);
  42. CTransactionWrap rhswrap(rhs.m_hcard);
  43. return CCryptObject::operator==(rhs) &&
  44. DoEquals(rhs);
  45. }
  46. bool
  47. CAbstractContainer::operator!=(CAbstractContainer const &rhs) const
  48. {
  49. return !(*this == rhs);
  50. }
  51. // Operations
  52. void
  53. CAbstractContainer::Delete()
  54. {
  55. CTransactionWrap wrap(m_hcard);
  56. // Delete all objects in this container
  57. Clear(ExchangeKeyPair());
  58. Clear(SignatureKeyPair());
  59. // If this container is the default container, re-set the default container
  60. if(m_hcard->DefaultContainer())
  61. {
  62. if (CContainer(this) == m_hcard->DefaultContainer())
  63. m_hcard->DefaultContainer(CContainer());
  64. }
  65. DoDelete();
  66. }
  67. // Access
  68. CKeyPair
  69. CAbstractContainer::ExchangeKeyPair()
  70. {
  71. CTransactionWrap wrap(m_hcard);
  72. CContainer cont(this);
  73. return CKeyPair(m_hcard, cont, ksExchange);
  74. }
  75. CKeyPair
  76. CAbstractContainer::GetKeyPair(KeySpec ks)
  77. {
  78. CKeyPair kp;
  79. CTransactionWrap wrap(m_hcard);
  80. CContainer cont(this);
  81. switch (ks)
  82. {
  83. case ksExchange:
  84. kp = CKeyPair(m_hcard, cont, ksExchange);
  85. break;
  86. case ksSignature:
  87. kp = CKeyPair(m_hcard, cont, ksSignature);
  88. break;
  89. default:
  90. throw Exception(ccBadKeySpec);
  91. }
  92. return kp;
  93. }
  94. CKeyPair
  95. CAbstractContainer::SignatureKeyPair()
  96. {
  97. CTransactionWrap wrap(m_hcard);
  98. CContainer cont(this);
  99. return CKeyPair(m_hcard, cont, ksSignature);
  100. }
  101. // Predicates
  102. bool
  103. CAbstractContainer::KeyPairExists(KeySpec ks)
  104. {
  105. bool fResult = true;
  106. CTransactionWrap wrap(m_hcard);
  107. CKeyPair kp(GetKeyPair(ks));
  108. if (!kp->PublicKey() && !kp->PrivateKey() && !kp->Certificate())
  109. fResult = false;
  110. return fResult;
  111. }
  112. // Static Variables
  113. /////////////////////////// PROTECTED /////////////////////////////////
  114. // C'tors/D'tors
  115. CAbstractContainer::CAbstractContainer(CAbstractCard const &racard)
  116. : slbRefCnt::RCObject(),
  117. CCryptObject(racard)
  118. {}
  119. // Operators
  120. // Operations
  121. // Access
  122. // Predicates
  123. // Static Variables
  124. /////////////////////////// PRIVATE /////////////////////////////////
  125. // C'tors/D'tors
  126. // Operators
  127. // Operations
  128. // Access
  129. // Predicates
  130. // Static Variables