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.

126 lines
4.6 KiB

  1. /* Copyright (C) Boris Nikolaus, Germany, 1996-1997. All rights reserved. */
  2. /* Copyright (C) Microsoft Corporation, 1997-1998. All rights reserved. */
  3. #include "precomp.h"
  4. static int _IsNotBounded(PERSimpleTypeInfo_t *sinfo);
  5. static int _IsUnsignedShortRange(PERSimpleTypeInfo_t *sinfo);
  6. static int _IsExtendedShortRange(PERSimpleTypeInfo_t *sinfo);
  7. int PerOptCase_IsSignedInteger(PERSimpleTypeInfo_t *sinfo)
  8. {
  9. return (sinfo->Data == ePERSTIData_Integer &&
  10. sinfo->Constraint == ePERSTIConstraint_Unconstrained &&
  11. sinfo->Length == ePERSTILength_InfiniteLength &&
  12. sinfo->NBits == 8 && // default
  13. sinfo->Alignment &&
  14. _IsNotBounded(sinfo) &&
  15. sinfo->LConstraint== ePERSTIConstraint_Semiconstrained &&
  16. sinfo->LLowerVal == 0 &&
  17. sinfo->LUpperVal == 0);
  18. }
  19. int PerOptCase_IsUnsignedInteger(PERSimpleTypeInfo_t *sinfo)
  20. {
  21. return (sinfo->Data == ePERSTIData_Unsigned &&
  22. sinfo->Constraint == ePERSTIConstraint_Semiconstrained &&
  23. sinfo->Length == ePERSTILength_InfiniteLength &&
  24. sinfo->NBits == 8 && // default
  25. sinfo->Alignment &&
  26. _IsNotBounded(sinfo) &&
  27. sinfo->LConstraint== ePERSTIConstraint_Semiconstrained &&
  28. sinfo->LLowerVal == 0 &&
  29. sinfo->LUpperVal == 0);
  30. }
  31. int PerOptCase_IsUnsignedShort(PERSimpleTypeInfo_t *sinfo)
  32. {
  33. return (sinfo->Data == ePERSTIData_Unsigned &&
  34. sinfo->Constraint == ePERSTIConstraint_Constrained &&
  35. sinfo->Length == ePERSTILength_NoLength &&
  36. sinfo->NBits == 16 &&
  37. sinfo->Alignment &&
  38. _IsUnsignedShortRange(sinfo) &&
  39. sinfo->LConstraint== ePERSTIConstraint_Semiconstrained &&
  40. sinfo->LLowerVal == 0 &&
  41. sinfo->LUpperVal == 0);
  42. }
  43. int PerOptCase_IsBoolean(PERSimpleTypeInfo_t *sinfo)
  44. {
  45. return (sinfo->Data == ePERSTIData_Boolean &&
  46. sinfo->Constraint == ePERSTIConstraint_Unconstrained &&
  47. sinfo->Length == ePERSTILength_NoLength &&
  48. sinfo->NBits == 1 &&
  49. ! sinfo->Alignment &&
  50. _IsNotBounded(sinfo) &&
  51. sinfo->LConstraint== ePERSTIConstraint_Semiconstrained &&
  52. sinfo->LLowerVal == 0 &&
  53. sinfo->LUpperVal == 0);
  54. }
  55. int PerOptCase_IsTargetSeqOf(PERTypeInfo_t *info)
  56. {
  57. return (
  58. // we only deal with singly linked-list case
  59. (info->Rules & eTypeRules_SinglyLinkedList)
  60. &&
  61. // check for size of sequence of/set of
  62. ((info->Root.LLowerVal == 0 && info->Root.LUpperVal == 0) ||
  63. (info->Root.LLowerVal < info->Root.LUpperVal)
  64. )
  65. &&
  66. // we do not deal with null body case
  67. (! (info->Root.SubType->Flags & eTypeFlags_Null))
  68. &&
  69. // we do not deal with recursive sequence of/set of
  70. (info->Root.SubType->PERTypeInfo.Root.Data != ePERSTIData_SequenceOf)
  71. &&
  72. (info->Root.SubType->PERTypeInfo.Root.Data != ePERSTIData_SetOf)
  73. &&
  74. // we only deal with sequence of or non-canonical set of.
  75. ((info->Root.Data == ePERSTIData_SequenceOf) ||
  76. (info->Root.Data == ePERSTIData_SetOf && g_eSubEncodingRule != eSubEncoding_Canonical))
  77. );
  78. }
  79. // UTILITIES
  80. static int _IsNotBounded(PERSimpleTypeInfo_t *sinfo)
  81. {
  82. return (sinfo->LowerVal.length == 1 &&
  83. sinfo->LowerVal.value[0] == 0 &&
  84. sinfo->UpperVal.length == 1 &&
  85. sinfo->UpperVal.value[0] == 0);
  86. }
  87. static int _IsUnsignedShortRange(PERSimpleTypeInfo_t *sinfo)
  88. {
  89. return ((sinfo->UpperVal.length < 3 ) ||
  90. (sinfo->UpperVal.length == 3 && sinfo->UpperVal.value[0] == 0 &&
  91. ! _IsExtendedShortRange(sinfo)));
  92. }
  93. static int _IsExtendedShortRange(PERSimpleTypeInfo_t *sinfo)
  94. {
  95. // if the lower bound is negative and the upper bound greater than 0x7FFF
  96. // then it is an extended short.
  97. return ((sinfo->LowerVal.length >= 1) &&
  98. (sinfo->LowerVal.value[0] & 0x80) && // lower bound is negative
  99. (sinfo->UpperVal.length == 3) &&
  100. (sinfo->UpperVal.value[0] == 0) && // upper bound is positive
  101. (*((ASN1uint16_t *) &(sinfo->UpperVal.value[1])) > 0x7FFF)); // upper bound greater than 0x7FFF
  102. }
  103. int BerOptCase_IsBoolean(BERTypeInfo_t *info)
  104. {
  105. return (eBERSTIData_Boolean == info->Data && 1 == info->NOctets);
  106. }