No Description

asn1_decoder.h 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (C) 2013 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef ASN1_DECODER_H_
  17. #define ASN1_DECODER_H_
  18. #include <stdint.h>
  19. class asn1_context {
  20. public:
  21. asn1_context(const uint8_t* buffer, size_t length) : p_(buffer), length_(length), app_type_(0) {}
  22. int asn1_constructed_type() const;
  23. asn1_context* asn1_constructed_get();
  24. bool asn1_constructed_skip_all();
  25. asn1_context* asn1_sequence_get();
  26. asn1_context* asn1_set_get();
  27. bool asn1_sequence_next();
  28. bool asn1_oid_get(const uint8_t** oid, size_t* length);
  29. bool asn1_octet_string_get(const uint8_t** octet_string, size_t* length);
  30. private:
  31. static constexpr int kMaskConstructed = 0xE0;
  32. static constexpr int kMaskTag = 0x7F;
  33. static constexpr int kMaskAppType = 0x1F;
  34. static constexpr int kTagOctetString = 0x04;
  35. static constexpr int kTagOid = 0x06;
  36. static constexpr int kTagSequence = 0x30;
  37. static constexpr int kTagSet = 0x31;
  38. static constexpr int kTagConstructed = 0xA0;
  39. int peek_byte() const;
  40. int get_byte();
  41. bool skip_bytes(size_t num_skip);
  42. bool decode_length(size_t* out_len);
  43. const uint8_t* p_;
  44. size_t length_;
  45. int app_type_;
  46. };
  47. #endif /* ASN1_DECODER_H_ */