Leaked source code of windows server 2003
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.

88 lines
1.8 KiB

  1. //=============================================================================
  2. //
  3. // MODULE: ASN1BitString.cxx
  4. //
  5. // Description:
  6. //
  7. // Implementation of ASN.1 bit string parsing logic
  8. //
  9. // Modification History
  10. //
  11. // Mark Pustilnik Date: 06/08/02 - created
  12. //
  13. //=============================================================================
  14. #include "ASN1Parser.hxx"
  15. //
  16. // Retrieve the value of an ASN.1-encoded bit string
  17. //
  18. DWORD
  19. ASN1ParserBitString::GetValue(
  20. IN OUT ASN1FRAME * Frame,
  21. OUT ASN1VALUE * Value
  22. )
  23. {
  24. DWORD dw;
  25. ASN1FRAME FrameIn = *Frame;
  26. DWORD DLength = DataLength( Frame );
  27. ULPBYTE Address = Frame->Address;
  28. if ( *Frame->Address != BuildDescriptor(
  29. ctUniversal,
  30. pcPrimitive,
  31. (BYTE)utBitString ))
  32. {
  33. dw = ERROR_INVALID_USER_BUFFER;
  34. goto Cleanup;
  35. }
  36. //
  37. // Skip over the the descriptor
  38. //
  39. Address++;
  40. //
  41. // Skip over the length header
  42. //
  43. Address += HeaderLength( Address );
  44. Value->Address = Address;
  45. Value->Length = DLength;
  46. Value->ut = utBitString;
  47. Value->dw = 0;
  48. //
  49. // NOTE: Netmon bitstring display facility does not seem to handle anything
  50. // longer than 4 bytes, but that's all we need in Kerberos anyway
  51. //
  52. for ( ULONG i = 0; i < DLength; i++ )
  53. {
  54. Value->dw <<= 8;
  55. Value->dw += *Address;
  56. Address++;
  57. }
  58. //
  59. // Mask off the bits we don't care about by making use of the bitmask
  60. //
  61. Value->dw &= m_BitMask;
  62. Frame->Address = Address;
  63. dw = ERROR_SUCCESS;
  64. Cleanup:
  65. if ( dw != ERROR_SUCCESS )
  66. {
  67. *Frame = FrameIn;
  68. }
  69. return dw;
  70. }