From b73820418346819b574434c5f5a0defd638a6dcc Mon Sep 17 00:00:00 2001 From: Sam Hartman Date: Wed, 23 Oct 2002 20:15:59 +0000 Subject: [PATCH] Implement asn1_encode_enumerated git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@14937 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/asn.1/ChangeLog | 10 ++++++++ src/lib/krb5/asn.1/asn1_encode.c | 41 ++++++++++++++++++++++++++++---- src/lib/krb5/asn.1/asn1_encode.h | 3 +++ src/lib/krb5/asn.1/krbasn1.h | 1 + 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/lib/krb5/asn.1/ChangeLog b/src/lib/krb5/asn.1/ChangeLog index db2fe2508..ed71c85b6 100644 --- a/src/lib/krb5/asn.1/ChangeLog +++ b/src/lib/krb5/asn.1/ChangeLog @@ -1,3 +1,13 @@ +2002-07-02 Sam Hartman + + * asn1_encode.h: Document asn1_encode_enumerated + + * asn1_encode.c (asn1_encode_enumerated): New function; split out + asn1_encode_integer's guts into asn1_encode_integer_interal and + add this function to add different universal tag for enumerated + + * krbasn1.h (ASN1_ENUMERATED): enumerated is universal 10 + 2002-10-07 Tom Yu * asn1_get.c (asn1_get_tag_indef): Stomp on asn1class, diff --git a/src/lib/krb5/asn.1/asn1_encode.c b/src/lib/krb5/asn.1/asn1_encode.c index 9bc9f5732..4c0345536 100644 --- a/src/lib/krb5/asn.1/asn1_encode.c +++ b/src/lib/krb5/asn.1/asn1_encode.c @@ -29,12 +29,11 @@ #include "asn1_encode.h" #include "asn1_make.h" -asn1_error_code asn1_encode_integer(asn1buf *buf, long val, - unsigned int *retlen) +static asn1_error_code asn1_encode_integer_internal(asn1buf *buf, long val, + unsigned int *retlen) { asn1_error_code retval; unsigned int length = 0; - unsigned int partlen; long valcopy; int digit; @@ -57,7 +56,41 @@ asn1_error_code asn1_encode_integer(asn1buf *buf, long val, length++; } - retval = asn1_make_tag(buf,UNIVERSAL,PRIMITIVE,ASN1_INTEGER,length, &partlen); + + *retlen = length; + return 0; +} + +asn1_error_code asn1_encode_integer(asn1buf * buf, long val, + unsigned int *retlen) +{ + asn1_error_code retval; + unsigned int length = 0; + unsigned int partlen; + retval = asn1_encode_integer_internal(buf, val, &partlen); + if (retval) return retval; + + length = partlen; + retval = asn1_make_tag(buf,UNIVERSAL,PRIMITIVE,ASN1_INTEGER,length, &partlen); + if(retval) return retval; + length += partlen; + + *retlen = length; + return 0; +} + +asn1_error_code +asn1_encode_enumerated(asn1buf * buf, const long val, + unsigned int *retlen) +{ + asn1_error_code retval; + unsigned int length = 0; + unsigned int partlen; + retval = asn1_encode_integer_internal(buf, val, &partlen); + if (retval) return retval; + + length = partlen; + retval = asn1_make_tag(buf,UNIVERSAL,PRIMITIVE,ASN1_ENUMERATED,length, &partlen); if(retval) return retval; length += partlen; diff --git a/src/lib/krb5/asn.1/asn1_encode.h b/src/lib/krb5/asn.1/asn1_encode.h index e5ae4bbb1..5c14800a4 100644 --- a/src/lib/krb5/asn.1/asn1_encode.h +++ b/src/lib/krb5/asn.1/asn1_encode.h @@ -58,6 +58,9 @@ asn1_error_code asn1_encode_integer Returns ENOMEM to signal an unsuccesful attempt to expand the buffer. */ +asn1_error_code asn1_encode_enumerated +(asn1buf *buf, const long val, unsigned int *retlen); + asn1_error_code asn1_encode_unsigned_integer (asn1buf *buf, const unsigned long val, unsigned int *retlen); diff --git a/src/lib/krb5/asn.1/krbasn1.h b/src/lib/krb5/asn.1/krbasn1.h index f4e23387a..7a45298ad 100644 --- a/src/lib/krb5/asn.1/krbasn1.h +++ b/src/lib/krb5/asn.1/krbasn1.h @@ -57,6 +57,7 @@ typedef int asn1_tagnum; #define ASN1_OCTETSTRING 4 #define ASN1_NULL 5 #define ASN1_OBJECTIDENTIFIER 6 +#define ASN1_ENUMERATED 10 #define ASN1_SEQUENCE 16 #define ASN1_SET 17 #define ASN1_PRINTABLESTRING 19 -- 2.26.2