summaryrefslogtreecommitdiffstats
path: root/asn1_decoder.h
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-03-22 18:09:14 +0100
committerandroid-build-merger <android-build-merger@google.com>2017-03-22 18:09:14 +0100
commit6e301018345e2290f1313960f99cda340e4f503f (patch)
tree7b0b21017701259738e60cbf260e00687b23f1b4 /asn1_decoder.h
parentMerge "Fix updater include generation w/installclean" am: 6d0262218a (diff)
parentMerge "Refactor asn1_decoder functions into a class." (diff)
downloadandroid_bootable_recovery-6e301018345e2290f1313960f99cda340e4f503f.tar
android_bootable_recovery-6e301018345e2290f1313960f99cda340e4f503f.tar.gz
android_bootable_recovery-6e301018345e2290f1313960f99cda340e4f503f.tar.bz2
android_bootable_recovery-6e301018345e2290f1313960f99cda340e4f503f.tar.lz
android_bootable_recovery-6e301018345e2290f1313960f99cda340e4f503f.tar.xz
android_bootable_recovery-6e301018345e2290f1313960f99cda340e4f503f.tar.zst
android_bootable_recovery-6e301018345e2290f1313960f99cda340e4f503f.zip
Diffstat (limited to 'asn1_decoder.h')
-rw-r--r--asn1_decoder.h45
1 files changed, 32 insertions, 13 deletions
diff --git a/asn1_decoder.h b/asn1_decoder.h
index fbd118f90..3e992115a 100644
--- a/asn1_decoder.h
+++ b/asn1_decoder.h
@@ -14,23 +14,42 @@
* limitations under the License.
*/
-
#ifndef ASN1_DECODER_H_
#define ASN1_DECODER_H_
#include <stdint.h>
-typedef struct asn1_context asn1_context_t;
-
-asn1_context_t* asn1_context_new(const uint8_t* buffer, size_t length);
-void asn1_context_free(asn1_context_t* ctx);
-asn1_context_t* asn1_constructed_get(asn1_context_t* ctx);
-bool asn1_constructed_skip_all(asn1_context_t* ctx);
-int asn1_constructed_type(asn1_context_t* ctx);
-asn1_context_t* asn1_sequence_get(asn1_context_t* ctx);
-asn1_context_t* asn1_set_get(asn1_context_t* ctx);
-bool asn1_sequence_next(asn1_context_t* seq);
-bool asn1_oid_get(asn1_context_t* ctx, const uint8_t** oid, size_t* length);
-bool asn1_octet_string_get(asn1_context_t* ctx, const uint8_t** octet_string, size_t* length);
+class asn1_context {
+ public:
+ asn1_context(const uint8_t* buffer, size_t length) : p_(buffer), length_(length), app_type_(0) {}
+ int asn1_constructed_type() const;
+ asn1_context* asn1_constructed_get();
+ bool asn1_constructed_skip_all();
+ asn1_context* asn1_sequence_get();
+ asn1_context* asn1_set_get();
+ bool asn1_sequence_next();
+ bool asn1_oid_get(const uint8_t** oid, size_t* length);
+ bool asn1_octet_string_get(const uint8_t** octet_string, size_t* length);
+
+ private:
+ static constexpr int kMaskConstructed = 0xE0;
+ static constexpr int kMaskTag = 0x7F;
+ static constexpr int kMaskAppType = 0x1F;
+
+ static constexpr int kTagOctetString = 0x04;
+ static constexpr int kTagOid = 0x06;
+ static constexpr int kTagSequence = 0x30;
+ static constexpr int kTagSet = 0x31;
+ static constexpr int kTagConstructed = 0xA0;
+
+ int peek_byte() const;
+ int get_byte();
+ bool skip_bytes(size_t num_skip);
+ bool decode_length(size_t* out_len);
+
+ const uint8_t* p_;
+ size_t length_;
+ int app_type_;
+};
#endif /* ASN1_DECODER_H_ */