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.

83 lines
1.6 KiB

  1. //=============================================================================
  2. //
  3. // MODULE: ASN1Integer.cxx
  4. //
  5. // Description:
  6. //
  7. // Implementation of ASN.1 integer 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 integer
  17. //
  18. DWORD
  19. ASN1ParserInteger::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)utInteger ))
  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 = utInteger;
  47. Value->dw = 0;
  48. for ( ULONG i = 0; i < DLength; i++ )
  49. {
  50. Value->dw <<= 8;
  51. Value->dw += *Address;
  52. Address++;
  53. }
  54. //
  55. // Mask off the bits we don't care about by making use of the bitmask
  56. //
  57. Value->dw &= m_BitMask;
  58. Frame->Address = Address;
  59. dw = ERROR_SUCCESS;
  60. Cleanup:
  61. if ( dw != ERROR_SUCCESS )
  62. {
  63. *Frame = FrameIn;
  64. }
  65. return dw;
  66. }