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.

152 lines
4.3 KiB

  1. // MsKeyBlob.cpp -- MicroSoft Key Blob class 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 "NoWarning.h"
  8. #include "ForceLib.h"
  9. #include <windows.h>
  10. #include <scuOsExc.h>
  11. #include "MsKeyBlob.h"
  12. using namespace scu;
  13. /////////////////////////// LOCAL/HELPER /////////////////////////////////
  14. /////////////////////////// PUBLIC /////////////////////////////////
  15. // Types
  16. // C'tors/D'tors
  17. // Operators
  18. // Operations
  19. // Access
  20. ALG_ID
  21. MsKeyBlob::AlgId() const
  22. {
  23. return reinterpret_cast<ValueType const *>(m_aapBlob.Get())->aiKeyAlg;
  24. }
  25. AlignedBlob
  26. MsKeyBlob::AsAlignedBlob() const
  27. {
  28. return AlignedBlob(m_aapBlob.Get(), m_cLength);
  29. }
  30. MsKeyBlob::ValueType const *
  31. MsKeyBlob::Data() const
  32. {
  33. return reinterpret_cast<ValueType const *>(m_aapBlob.Get());
  34. }
  35. MsKeyBlob::SizeType
  36. MsKeyBlob::Length() const
  37. {
  38. return m_cLength;
  39. }
  40. // Predicates
  41. // Static Variables
  42. /////////////////////////// PROTECTED /////////////////////////////////
  43. // C'tors/D'tors
  44. MsKeyBlob::MsKeyBlob(KeyBlobType kbt,
  45. ALG_ID ai,
  46. SizeType cReserve)
  47. : m_aapBlob(0),
  48. m_cLength(0),
  49. m_cMaxSize(0)
  50. {
  51. Setup(sizeof HeaderElementType + cReserve);
  52. ValueType bhTemplate =
  53. {
  54. kbt,
  55. CUR_BLOB_VERSION,
  56. 0, // must be zero per MS
  57. ai
  58. };
  59. Append(reinterpret_cast<BlobElemType const *>(&bhTemplate),
  60. sizeof bhTemplate);
  61. }
  62. MsKeyBlob::MsKeyBlob(BYTE const *pbData,
  63. DWORD dwDataLength)
  64. : m_aapBlob(0),
  65. m_cLength(0),
  66. m_cMaxSize(0)
  67. {
  68. Setup(dwDataLength);
  69. ValueType const *pvt = reinterpret_cast<ValueType const *>(pbData);
  70. if (!((PUBLICKEYBLOB == pvt->bType) ||
  71. (PRIVATEKEYBLOB == pvt->bType) ||
  72. (SIMPLEBLOB == pvt->bType)))
  73. throw scu::OsException(NTE_BAD_TYPE);
  74. if (CUR_BLOB_VERSION != pvt->bVersion)
  75. throw scu::OsException(NTE_BAD_TYPE);
  76. if (0 != pvt->reserved)
  77. throw scu::OsException(NTE_BAD_TYPE);
  78. Append(pbData, dwDataLength);
  79. }
  80. MsKeyBlob::~MsKeyBlob()
  81. {}
  82. // Operators
  83. // Operations
  84. void
  85. MsKeyBlob::Append(BlobElemType const *pvt,
  86. SizeType cLength)
  87. {
  88. if ((m_cLength + cLength) > m_cMaxSize)
  89. {
  90. size_t cNewMax = m_cMaxSize + cLength;
  91. AutoArrayPtr<BlobElemType> aapTemp(AllocBlob(cNewMax));
  92. memcpy(aapTemp.Get(), m_aapBlob.Get(), m_cLength);
  93. m_aapBlob = aapTemp;
  94. m_cMaxSize = cNewMax;
  95. }
  96. memcpy(m_aapBlob.Get() + m_cLength, pvt, cLength);
  97. m_cLength += cLength;
  98. }
  99. // Access
  100. // Predicates
  101. // Static Variables
  102. /////////////////////////// PRIVATE /////////////////////////////////
  103. // C'tors/D'tors
  104. // Operators
  105. // Operations
  106. AutoArrayPtr<MsKeyBlob::BlobElemType>
  107. MsKeyBlob::AllocBlob(MsKeyBlob::SizeType cInitialMaxLength)
  108. {
  109. return AutoArrayPtr<BlobElemType>(new BlobElemType[cInitialMaxLength]);
  110. }
  111. void
  112. MsKeyBlob::Setup(MsKeyBlob::SizeType cMaxLength)
  113. {
  114. m_aapBlob = AllocBlob(cMaxLength);
  115. m_cLength = 0;
  116. m_cMaxSize = cMaxLength;
  117. }
  118. // Access
  119. // Predicates
  120. // Static Variables