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.

196 lines
3.7 KiB

  1. /*
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. sdpenc.cpp
  5. Abstract:
  6. Author:
  7. */
  8. #include "sdppch.h"
  9. #include "sdpenc.h"
  10. #include "sdpltran.h"
  11. // line transition states
  12. enum ENCRYPTION_TRANSITION_STATES
  13. {
  14. ENCRYPTION_START,
  15. ENCRYPTION_KEY_TYPE,
  16. ENCRYPTION_KEY_TYPE_END,
  17. ENCRYPTION_KEY_DATA_END
  18. };
  19. // table for connection line transitions
  20. const LINE_TRANSITION g_EncryptionStartTransitions[] = {
  21. {CHAR_NEWLINE, ENCRYPTION_KEY_TYPE_END },
  22. {CHAR_COLON, ENCRYPTION_KEY_TYPE }
  23. };
  24. const LINE_TRANSITION g_EncryptionKeyTypeTransitions[] = {
  25. {CHAR_NEWLINE, ENCRYPTION_KEY_DATA_END }
  26. };
  27. /* no transitions */
  28. const LINE_TRANSITION *g_EncryptionKeyTypeEndTransitions= NULL;
  29. /* no transitions */
  30. const LINE_TRANSITION *g_EncryptionKeyDataEndTransitions= NULL;
  31. LINE_TRANSITION_INFO g_EncryptionTransitionInfo[] = {
  32. LINE_TRANSITION_ENTRY(ENCRYPTION_START, g_EncryptionStartTransitions),
  33. LINE_TRANSITION_ENTRY(ENCRYPTION_KEY_TYPE, g_EncryptionKeyTypeTransitions),
  34. LINE_TRANSITION_ENTRY(ENCRYPTION_KEY_TYPE_END, g_EncryptionKeyTypeEndTransitions),
  35. LINE_TRANSITION_ENTRY(ENCRYPTION_KEY_DATA_END, g_EncryptionKeyDataEndTransitions)
  36. };
  37. SDP_LINE_TRANSITION g_EncryptionTransition(
  38. g_EncryptionTransitionInfo,
  39. sizeof(g_EncryptionTransitionInfo)/sizeof(LINE_TRANSITION_INFO)
  40. );
  41. SDP_ENCRYPTION_KEY::SDP_ENCRYPTION_KEY(
  42. )
  43. : SDP_VALUE(SDP_INVALID_ENCRYPTION_KEY_FIELD, KEY_STRING, &g_EncryptionTransition)
  44. {}
  45. void
  46. SDP_ENCRYPTION_KEY::InternalReset(
  47. )
  48. {
  49. m_KeyType.Reset();
  50. m_KeyData.Reset();
  51. }
  52. HRESULT
  53. SDP_ENCRYPTION_KEY::SetKey(
  54. IN BSTR KeyType,
  55. IN BSTR *KeyData
  56. )
  57. {
  58. // set the key type field
  59. HRESULT ToReturn = m_KeyType.SetBstr(KeyType);
  60. if ( FAILED(ToReturn) )
  61. {
  62. return ToReturn;
  63. }
  64. // if required, set the key data field
  65. if ( NULL != KeyData )
  66. {
  67. ToReturn = m_KeyData.SetBstr(*KeyData);
  68. if ( FAILED(ToReturn) )
  69. {
  70. return ToReturn;
  71. }
  72. }
  73. else
  74. {
  75. m_KeyData.Reset();
  76. }
  77. m_FieldArray.RemoveAll();
  78. m_SeparatorCharArray.RemoveAll();
  79. if ( NULL != KeyData )
  80. {
  81. try
  82. {
  83. // set the field/separator chars
  84. m_FieldArray.SetAtGrow(0, &m_KeyType);
  85. m_SeparatorCharArray.SetAtGrow(0, CHAR_COLON);
  86. m_FieldArray.SetAtGrow(1, &m_KeyData);
  87. m_SeparatorCharArray.SetAtGrow(1, CHAR_NEWLINE);
  88. }
  89. catch(...)
  90. {
  91. m_FieldArray.RemoveAll();
  92. m_SeparatorCharArray.RemoveAll();
  93. return E_OUTOFMEMORY;
  94. }
  95. }
  96. else
  97. {
  98. try
  99. {
  100. // set the field/separator chars
  101. m_FieldArray.SetAtGrow(0, &m_KeyType);
  102. m_SeparatorCharArray.SetAtGrow(0, CHAR_NEWLINE);
  103. }
  104. catch(...)
  105. {
  106. m_FieldArray.RemoveAll();
  107. m_SeparatorCharArray.RemoveAll();
  108. return E_OUTOFMEMORY;
  109. }
  110. }
  111. return S_OK;
  112. }
  113. BOOL
  114. SDP_ENCRYPTION_KEY::GetField(
  115. OUT SDP_FIELD *&Field,
  116. OUT BOOL &AddToArray
  117. )
  118. {
  119. // add in all cases by default
  120. AddToArray = TRUE;
  121. switch(m_LineState)
  122. {
  123. case ENCRYPTION_KEY_TYPE:
  124. case ENCRYPTION_KEY_TYPE_END:
  125. {
  126. Field = &m_KeyType;
  127. }
  128. break;
  129. case ENCRYPTION_KEY_DATA_END:
  130. {
  131. Field = &m_KeyData;
  132. }
  133. break;
  134. default:
  135. {
  136. SetLastError(m_ErrorCode);
  137. return FALSE;
  138. }
  139. break;
  140. };
  141. return TRUE;
  142. }