lib/krb5/krb/strptime.c
OTHEREXCLUDES = \
- lib/krb5/asn.1 \
+ lib/krb5/asn.1/asn1_decode.h \
+ lib/krb5/asn.1/asn1_encode.h \
+ lib/krb5/asn.1/asn1_k_encode.c \
+ lib/krb5/asn.1/asn1_make.h \
+ lib/krb5/asn.1/asn1buf.h \
+ lib/krb5/asn.1/krb5_decode.c \
lib/krb5/krb/deltat.c \
lib/krb5/unicode
return 0;
}
-/* ASN.1 constructed type encoder engine
-
- Two entry points here:
-
- krb5int_asn1_encode_a_thing: Incrementally adds the partial
- encoding of an object to an already-initialized asn1buf.
-
- krb5int_asn1_do_full_encode: Returns a completed encoding, in the
- correct byte order, in an allocated krb5_data. */
+/*
+ * ASN.1 constructed type encoder engine
+ *
+ * Two entry points here:
+ *
+ * krb5int_asn1_encode_a_thing: Incrementally adds the partial
+ * encoding of an object to an already-initialized asn1buf.
+ *
+ * krb5int_asn1_do_full_encode: Returns a completed encoding, in the
+ * correct byte order, in an allocated krb5_data.
+ */
#ifdef POINTERS_ARE_ALL_THE_SAME
#define LOADPTR(PTR,TYPE) \
unsigned int length;
const struct atype_info *a;
- /* The field holds a pointer to the array of objects. So the
- address we compute is a pointer-to-pointer, and that's what
- field->atype must help us dereference. */
+ /*
+ * The field holds a pointer to the array of objects. So the
+ * address we compute is a pointer-to-pointer, and that's what
+ * field->atype must help us dereference.
+ */
dataptr = (const char *)val + field->dataoff;
lenptr = (const char *)val + field->lenoff;
assert(field->atype->type == atype_ptr);
return EINVAL;
if (dataptr == NULL && slen != 0)
return ASN1_MISSING_FIELD;
- /* Currently our string encoders want "unsigned int" for
- lengths. */
+ /*
+ * Currently our string encoders want "unsigned int" for
+ * lengths.
+ */
if (slen != (unsigned int) slen)
return EINVAL;
assert(a->enclen != NULL);
if (seq->optional)
optional = seq->optional(val);
else
- /* In this case, none of the field descriptors should indicate
- that we examine any bits of this value. */
+ /*
+ * In this case, none of the field descriptors should indicate
+ * that we examine any bits of this value.
+ */
optional = 0;
{
unsigned int length;
#include "asn1buf.h"
typedef struct {
-#if 1 /* Smaller run-time storage, and on x86 the compiler can use
- byte loads, stores, and compares, but on other platforms the
- compiler may need to load and widen before comparing... see
- how this works out. */
+#if 1
+ /*
+ * Smaller run-time storage, and on x86 the compiler can use byte
+ * loads, stores, and compares, but on other platforms the compiler
+ * may need to load and widen before comparing... see how this works
+ * out.
+ */
unsigned int asn1class : 8, construction : 8;
#else
asn1_class asn1class;
asn1_construction *construction,
asn1_tagnum *tagnum,
unsigned int *retlen);
-/* requires *buf is allocated
- effects Decodes the tag in *buf. If class != NULL, returns
- the class in *Class. Similarly, the construction,
- tag number, and length are returned in *construction,
- *tagnum, and *retlen, respectively.
- If *buf is empty to begin with,
- *tagnum is set to ASN1_TAGNUM_CEILING.
- Returns ASN1_OVERRUN if *buf is exhausted during the parse. */
+/*
+ * requires *buf is allocated
+ * effects Decodes the tag in *buf. If class != NULL, returns
+ * the class in *Class. Similarly, the construction,
+ * tag number, and length are returned in *construction,
+ * *tagnum, and *retlen, respectively.
+ *
+ * If *buf is empty to begin with, *tagnum is set to
+ * ASN1_TAGNUM_CEILING.
+ *
+ * Returns ASN1_OVERRUN if *buf is exhausted during the
+ * parse.
+ */
#endif
asn1_error_code asn1_get_sequence(asn1buf *buf, unsigned int *retlen,
int *indef);
-/* requires *buf is allocated
- effects Decodes a tag from *buf and returns ASN1_BAD_ID if it
- doesn't have a sequence ID. If retlen != NULL, the
- associated length is returned in *retlen. */
-
+/*
+ * requires *buf is allocated
+ * effects Decodes a tag from *buf and returns ASN1_BAD_ID if it
+ * doesn't have a sequence ID. If retlen != NULL, the
+ * associated length is returned in *retlen.
+ */
#endif
#include "asn1buf.h"
/* asn1_error_code asn1_decode_scalar_type(asn1buf *buf, krb5_scalar *val); */
-/* requires *buf is allocated, *buf's current position points to the
- beginning of an encoding (<id> <len> <contents>),
- *val is allocated
- effects Decodes the encoding in *buf, returning the result in *val.
- Returns ASN1_BAD_ID if the encoded id does not
- indicate the proper type.
- Returns ASN1_OVERRUN if the encoded length exceeds
- the bounds of *buf */
-
-
-/* asn1_error_code asn1_decode_structure_type(asn1buf *buf,
- krb5_structure *val); */
-/* requires *buf is allocated, *buf's current position points to the
- beginning of an encoding (<id> <len> <contents>),
- *val is allocated
- Assumes that *val is a freshly-allocated structure (i.e.
- does not attempt to clean up or free *val).
- effects Decodes the encoding in *buf, returning the result in *val.
- Returns ASN1_BAD_ID if the encoded id does not
- indicate the proper type.
- Returns ASN1_OVERRUN if the encoded length exceeds
- the bounds of *buf */
+/*
+ * requires *buf is allocated, *buf's current position points to the
+ * beginning of an encoding (<id> <len> <contents>),
+ * *val is allocated
+ *
+ * effects Decodes the encoding in *buf, returning the result in *val.
+ *
+ * Returns ASN1_BAD_ID if the encoded id does not indicate
+ * the proper type.
+ *
+ * Returns ASN1_OVERRUN if the encoded length exceeds
+ * the bounds of *buf
+ */
+
+
+/*
+ * asn1_error_code asn1_decode_structure_type(asn1buf *buf,
+ * krb5_structure *val);
+ */
+/*
+ * requires *buf is allocated, *buf's current position points to the
+ * beginning of an encoding (<id> <len> <contents>),
+ * *val is allocated
+ *
+ * Assumes that *val is a freshly-allocated structure (i.e.
+ * does not attempt to clean up or free *val).
+ * effects Decodes the encoding in *buf, returning the result in *val.
+ *
+ * Returns ASN1_BAD_ID if the encoded id does not indicate
+ * the proper type.
+ *
+ * Returns ASN1_OVERRUN if the encoded length exceeds the
+ * bounds of *buf
+ */
/* asn1_error_code asn1_decode_array_type(asn1buf *buf, krb5_scalar ***val); */
-/* requires *buf is allocated, *buf's current position points to the
- beginning of an encoding (<id> <len> <contents>)
- Assumes that *val is empty (i.e. does not attempt to
- clean up or free *val).
- effects Decodes the encoding in *buf, returning the result in *val.
- Returns ASN1_BAD_ID if the encoded id does not
- indicate the proper type.
- Returns ASN1_OVERRUN if the encoded length exceeds
- the bounds of *buf */
+/*
+ * requires *buf is allocated, *buf's current position points to the
+ * beginning of an encoding (<id> <len> <contents>)
+ *
+ * Assumes that *val is empty (i.e. does not attempt to
+ * clean up or free *val).
+ *
+ * effects Decodes the encoding in *buf, returning the result in *val.
+ *
+ * Returns ASN1_BAD_ID if the encoded id does not indicate
+ * the proper type.
+ *
+ * Returns ASN1_OVERRUN if the encoded length exceeds the
+ * bounds of *buf
+ */
/* scalars */
asn1_error_code asn1_decode_int(asn1buf *buf, int *val);
#include "asn1buf.h"
/*
-**** for simple val's ****
-asn1_error_code asn1_encode_asn1_type(asn1buf *buf,
- const krb5_type val,
- int *retlen);
- requires *buf is allocated
- effects Inserts the encoding of val into *buf and
- returns the length of this encoding in *retlen.
- Returns ASN1_MISSING_FIELD if a required field is empty in val.
- Returns ENOMEM if memory runs out.
-
-**** for struct val's ****
-asn1_error_code asn1_encode_asn1_type(asn1buf *buf,
- const krb5_type *val,
- int *retlen);
- requires *buf is allocated
- effects Inserts the encoding of *val into *buf and
- returns the length of this encoding in *retlen.
- Returns ASN1_MISSING_FIELD if a required field is empty in val.
- Returns ENOMEM if memory runs out.
-
-**** for array val's ****
-asn1_error_code asn1_encode_asn1_type(asn1buf *buf,
- const krb5_type **val,
- int *retlen);
- requires *buf is allocated, **val != NULL, *val[0] != NULL,
- **val is a NULL-terminated array of pointers to krb5_type
- effects Inserts the encoding of **val into *buf and
- returns the length of this encoding in *retlen.
- Returns ASN1_MISSING_FIELD if a required field is empty in val.
- Returns ENOMEM if memory runs out.
-*/
+ * **** for simple val's ****
+ * asn1_error_code asn1_encode_asn1_type(asn1buf *buf,
+ * const krb5_type val,
+ * int *retlen);
+ * requires *buf is allocated
+ * effects Inserts the encoding of val into *buf and
+ * returns the length of this encoding in *retlen.
+ * Returns ASN1_MISSING_FIELD if a required field is empty in val.
+ * Returns ENOMEM if memory runs out.
+ *
+ * **** for struct val's ****
+ * asn1_error_code asn1_encode_asn1_type(asn1buf *buf,
+ * const krb5_type *val,
+ * int *retlen);
+ * requires *buf is allocated
+ * effects Inserts the encoding of *val into *buf and
+ * returns the length of this encoding in *retlen.
+ * Returns ASN1_MISSING_FIELD if a required field is empty in val.
+ * Returns ENOMEM if memory runs out.
+ *
+ * **** for array val's ****
+ * asn1_error_code asn1_encode_asn1_type(asn1buf *buf,
+ * const krb5_type **val,
+ * int *retlen);
+ * requires *buf is allocated, **val != NULL, *val[0] != NULL,
+ * **val is a NULL-terminated array of pointers to krb5_type
+ * effects Inserts the encoding of **val into *buf and
+ * returns the length of this encoding in *retlen.
+ * Returns ASN1_MISSING_FIELD if a required field is empty in val.
+ * Returns ENOMEM if memory runs out.
+ */
/* PKINIT */
asn1_error_code asn1_krb5_realm_copy(krb5_principal target,
krb5_principal source);
-/* requires target, source, and source->realm are allocated
- effects Copies source->realm into target->realm.
- Returns ENOMEM if memory is exhausted. */
+/*
+ * requires target, source, and source->realm are allocated
+ * effects Copies source->realm into target->realm.
+ * Returns ENOMEM if memory is exhausted.
+ */
#endif
/* Coding Buffer Implementation */
/*
- Implementation
+ * Implementation
+ *
+ * Encoding mode
+ *
+ * The encoding buffer is filled from bottom (lowest address) to top
+ * (highest address). This makes it easier to expand the buffer,
+ * since realloc preserves the existing portion of the buffer.
+ *
+ * Note: Since ASN.1 encoding must be done in reverse, this means
+ * that you can't simply memcpy out the buffer data, since it will be
+ * backwards. You need to reverse-iterate through it, instead.
+ *
+ * ***This decision may have been a mistake. In practice, the
+ * implementation will probably be tuned such that reallocation is
+ * rarely necessary. Also, the realloc probably has recopy the
+ * buffer itself, so we don't really gain that much by avoiding an
+ * explicit copy of the buffer. --Keep this in mind for future reference.
+ *
+ *
+ * Decoding mode
+ *
+ * The decoding buffer is in normal order and is created by wrapping
+ * an asn1buf around a krb5_data structure.
+ */
- Encoding mode
-
- The encoding buffer is filled from bottom (lowest address) to top
- (highest address). This makes it easier to expand the buffer,
- since realloc preserves the existing portion of the buffer.
-
- Note: Since ASN.1 encoding must be done in reverse, this means
- that you can't simply memcpy out the buffer data, since it will be
- backwards. You need to reverse-iterate through it, instead.
-
- ***This decision may have been a mistake. In practice, the
- implementation will probably be tuned such that reallocation is
- rarely necessary. Also, the realloc probably has recopy the
- buffer itself, so we don't really gain that much by avoiding an
- explicit copy of the buffer. --Keep this in mind for future reference.
-
-
- Decoding mode
-
- The decoding buffer is in normal order and is created by wrapping
- an asn1buf around a krb5_data structure.
- */
-
-/* Abstraction Function
-
- Programs should use just pointers to asn1buf's (e.g. asn1buf *mybuf).
- These pointers must always point to a valid, allocated asn1buf
- structure or be NULL.
-
- The contents of the asn1buf represent an octet string. This string
- begins at base and continues to the octet immediately preceding next.
- If next == base or mybuf == NULL, then the asn1buf represents an empty
- octet string. */
-
-/* Representation Invariant
-
- Pointers to asn1buf's must always point to a valid, allocated
- asn1buf structure or be NULL.
+/*
+ * Abstraction Function
+ *
+ * Programs should use just pointers to asn1buf's (e.g. asn1buf *mybuf).
+ * These pointers must always point to a valid, allocated asn1buf
+ * structure or be NULL.
+ *
+ * The contents of the asn1buf represent an octet string. This string
+ * begins at base and continues to the octet immediately preceding next.
+ * If next == base or mybuf == NULL, then the asn1buf represents an empty
+ * octet string.
+ */
- base points to a valid, allocated octet array or is NULL
- bound, if non-NULL, points to the last valid octet
- next >= base
- next <= bound+2 (i.e. next should be able to step just past the bound,
- but no further. (The bound should move out in response
- to being crossed by next.)) */
+/*
+ * Representation Invariant
+ *
+ * Pointers to asn1buf's must always point to a valid, allocated
+ * asn1buf structure or be NULL.
+ *
+ * base points to a valid, allocated octet array or is NULL
+ * bound, if non-NULL, points to the last valid octet
+ * next >= base
+ * next <= bound+2 (i.e. next should be able to step just past the bound,
+ * but no further. (The bound should move out in response
+ * to being crossed by next.))
+ */
#define ASN1BUF_OMIT_INLINE_FUNCS
#include "asn1buf.h"
#endif
#if !defined(__GNUC__) || defined(CONFIG_SMALL)
-/* Declare private procedures as static if they're not used for inline
- expansion of other stuff elsewhere. */
+/*
+ * Declare private procedures as static if they're not used for inline
+ * expansion of other stuff elsewhere.
+ */
static unsigned int asn1buf_free(const asn1buf *);
static asn1_error_code asn1buf_ensure_space(asn1buf *, unsigned int);
static asn1_error_code asn1buf_expand(asn1buf *, unsigned int);
-/* These parse and unparse procedures should be moved out. They're
- useful only for debugging and superfluous in the production version. */
+/*
+ * These parse and unparse procedures should be moved out. They're
+ * useful only for debugging and superfluous in the production
+ * version.
+ */
asn1_error_code asn1buf_unparse(const asn1buf *buf, char **s)
{
/**************** Macros (these save a lot of typing) ****************/
-/* setup() -- create and initialize bookkeeping variables
- retval: stores error codes returned from subroutines
- buf: the coding buffer
- length: length of the most-recently produced encoding
- sum: cumulative length of the entire encoding */
+/*
+ * setup() -- create and initialize bookkeeping variables
+ * retval: stores error codes returned from subroutines
+ * buf: the coding buffer
+ * length: length of the most-recently produced encoding
+ * sum: cumulative length of the entire encoding
+ */
#define krb5_setup()\
asn1_error_code retval;\
unsigned int length, sum = 0;\
/* -*- mode: c; indent-tabs-mode: nil -*- */
/* ... copyright ... */
-/* Novell key-format scheme:
-
- KrbKeySet ::= SEQUENCE {
- attribute-major-vno [0] UInt16,
- attribute-minor-vno [1] UInt16,
- kvno [2] UInt32,
- mkvno [3] UInt32 OPTIONAL,
- keys [4] SEQUENCE OF KrbKey,
- ...
- }
-
- KrbKey ::= SEQUENCE {
- salt [0] KrbSalt OPTIONAL,
- key [1] EncryptionKey,
- s2kparams [2] OCTET STRING OPTIONAL,
- ...
- }
-
- KrbSalt ::= SEQUENCE {
- type [0] Int32,
- salt [1] OCTET STRING OPTIONAL
- }
-
- EncryptionKey ::= SEQUENCE {
- keytype [0] Int32,
- keyvalue [1] OCTET STRING
- }
-
+/*
+ * Novell key-format scheme:
+ *
+ * KrbKeySet ::= SEQUENCE {
+ * attribute-major-vno [0] UInt16,
+ * attribute-minor-vno [1] UInt16,
+ * kvno [2] UInt32,
+ * mkvno [3] UInt32 OPTIONAL,
+ * keys [4] SEQUENCE OF KrbKey,
+ * ...
+ * }
+ *
+ * KrbKey ::= SEQUENCE {
+ * salt [0] KrbSalt OPTIONAL,
+ * key [1] EncryptionKey,
+ * s2kparams [2] OCTET STRING OPTIONAL,
+ * ...
+ * }
+ *
+ * KrbSalt ::= SEQUENCE {
+ * type [0] Int32,
+ * salt [1] OCTET STRING OPTIONAL
+ * }
+ *
+ * EncryptionKey ::= SEQUENCE {
+ * keytype [0] Int32,
+ * keyvalue [1] OCTET STRING
+ * }
+ *
*/
#include <k5-int.h>
/* Encode the Principal's keys */
/************************************************************************/
-/* Imports from asn1_k_encode.c.
- XXX Must be manually synchronized for now. */
+/*
+ * Imports from asn1_k_encode.c.
+ * XXX Must be manually synchronized for now.
+ */
IMPORT_TYPE(octetstring, unsigned char *);
IMPORT_TYPE(int32, krb5_int32);