Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

63 rader
2.2 KiB

  1. /* Copyright (c) 2016, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #include <stdio.h>
  15. #include <gtest/gtest.h>
  16. #include <openssl/asn1.h>
  17. #include <openssl/err.h>
  18. #include "../test/test_util.h"
  19. // kTag128 is an ASN.1 structure with a universal tag with number 128.
  20. static const uint8_t kTag128[] = {
  21. 0x1f, 0x81, 0x00, 0x01, 0x00,
  22. };
  23. // kTag258 is an ASN.1 structure with a universal tag with number 258.
  24. static const uint8_t kTag258[] = {
  25. 0x1f, 0x82, 0x02, 0x01, 0x00,
  26. };
  27. static_assert(V_ASN1_NEG_INTEGER == 258,
  28. "V_ASN1_NEG_INTEGER changed. Update kTag258 to collide with it.");
  29. // kTagOverflow is an ASN.1 structure with a universal tag with number 2^35-1,
  30. // which will not fit in an int.
  31. static const uint8_t kTagOverflow[] = {
  32. 0x1f, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x01, 0x00,
  33. };
  34. TEST(ASN1Test, LargeTags) {
  35. const uint8_t *p = kTag258;
  36. bssl::UniquePtr<ASN1_TYPE> obj(d2i_ASN1_TYPE(NULL, &p, sizeof(kTag258)));
  37. EXPECT_FALSE(obj) << "Parsed value with illegal tag" << obj->type;
  38. ERR_clear_error();
  39. p = kTagOverflow;
  40. obj.reset(d2i_ASN1_TYPE(NULL, &p, sizeof(kTagOverflow)));
  41. EXPECT_FALSE(obj) << "Parsed value with tag overflow" << obj->type;
  42. ERR_clear_error();
  43. p = kTag128;
  44. obj.reset(d2i_ASN1_TYPE(NULL, &p, sizeof(kTag128)));
  45. ASSERT_TRUE(obj);
  46. EXPECT_EQ(128, obj->type);
  47. const uint8_t kZero = 0;
  48. EXPECT_EQ(Bytes(&kZero, 1), Bytes(obj->value.asn1_string->data,
  49. obj->value.asn1_string->length));
  50. }