@@ -179,12 +179,9 @@ extern "C" {
179
179
// When representing a BIT STRING value, the type field is |V_ASN1_BIT_STRING|.
180
180
// See bit string documentation below for how the data and flags are used.
181
181
//
182
- // When representing an INTEGER or ENUMERATED value, the data contains the
183
- // big-endian encoding of the absolute value of the integer. The sign bit is
184
- // encoded in the type: non-negative values have a type of |V_ASN1_INTEGER| or
185
- // |V_ASN1_ENUMERATED|, while negative values have a type of
186
- // |V_ASN1_NEG_INTEGER| or |V_ASN1_NEG_ENUMERATED|. Note this differs from DER's
187
- // two's complement representation.
182
+ // When representing an INTEGER or ENUMERATED value, the type field is one of
183
+ // |V_ASN1_INTEGER|, |V_ASN1_NEG_INTEGER|, |V_ASN1_ENUMERATED|, or
184
+ // |V_ASN1_NEG_ENUMERATED|. See integer documentation below for details.
188
185
//
189
186
// When representing a GeneralizedTime or UTCTime value, the type field is
190
187
// |V_ASN1_GENERALIZEDTIME| or |V_ASN1_UTCTIME|, respectively. The data contains
@@ -284,11 +281,16 @@ OPENSSL_EXPORT int ASN1_STRING_length(const ASN1_STRING *str);
284
281
285
282
// ASN1_STRING_cmp compares |a| and |b|'s type and contents. It returns an
286
283
// integer equal to, less than, or greater than zero if |a| is equal to, less
287
- // than, or greater than |b|, respectively. The comparison is suitable for
288
- // sorting, but callers should not rely on the particular comparison.
284
+ // than, or greater than |b|, respectively. This function compares by length,
285
+ // then data, then type. Note the data compared is the |ASN1_STRING| internal
286
+ // representation and the type order is arbitrary. While this comparison is
287
+ // suitable for sorting, callers should not rely on the exact order when |a|
288
+ // and |b| are different types.
289
289
//
290
- // Note if |a| or |b| are BIT STRINGs, this function does not compare the
291
- // |ASN1_STRING_FLAG_BITS_LEFT| flags.
290
+ // If |a| or |b| are BIT STRINGs, this function does not compare the
291
+ // |ASN1_STRING_FLAG_BITS_LEFT| flags. Additionally, if |a| and |b| are
292
+ // INTEGERs, this comparison does not order the values numerically. For a
293
+ // numerical comparison, use |ASN1_INTEGER_cmp|.
292
294
//
293
295
// TODO(davidben): The BIT STRING comparison seems like a bug. Fix it?
294
296
OPENSSL_EXPORT int ASN1_STRING_cmp (const ASN1_STRING * a , const ASN1_STRING * b );
@@ -387,6 +389,69 @@ OPENSSL_EXPORT int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *str,
387
389
// TODO(davidben): Expand and document function prototypes generated in macros.
388
390
389
391
392
+ // Integers and enumerated values.
393
+ //
394
+ // INTEGER and ENUMERATED values are represented as |ASN1_STRING|s where the
395
+ // data contains the big-endian encoding of the absolute value of the integer.
396
+ // The sign bit is encoded in the type: non-negative values have a type of
397
+ // |V_ASN1_INTEGER| or |V_ASN1_ENUMERATED|, while negative values have a type of
398
+ // |V_ASN1_NEG_INTEGER| or |V_ASN1_NEG_ENUMERATED|. Note this differs from DER's
399
+ // two's complement representation.
400
+
401
+ // ASN1_INTEGER_set sets |a| to an INTEGER with value |v|. It returns one on
402
+ // success and zero on error.
403
+ OPENSSL_EXPORT int ASN1_INTEGER_set (ASN1_INTEGER * a , long v );
404
+
405
+ // ASN1_INTEGER_set sets |a| to an INTEGER with value |v|. It returns one on
406
+ // success and zero on error.
407
+ OPENSSL_EXPORT int ASN1_INTEGER_set_uint64 (ASN1_INTEGER * out , uint64_t v );
408
+
409
+ // ASN1_INTEGER_get returns the value of |a| as a |long|, or -1 if |a| is out of
410
+ // range or the wrong type.
411
+ OPENSSL_EXPORT long ASN1_INTEGER_get (const ASN1_INTEGER * a );
412
+
413
+ // BN_to_ASN1_INTEGER sets |ai| to an INTEGER with value |bn| and returns |ai|
414
+ // on success or NULL or error. If |ai| is NULL, it returns a newly-allocated
415
+ // |ASN1_INTEGER| on success instead, which the caller must release with
416
+ // |ASN1_INTEGER_free|.
417
+ OPENSSL_EXPORT ASN1_INTEGER * BN_to_ASN1_INTEGER (const BIGNUM * bn ,
418
+ ASN1_INTEGER * ai );
419
+
420
+ // ASN1_INTEGER_to_BN sets |bn| to the value of |ai| and returns |bn| on success
421
+ // or NULL or error. If |bn| is NULL, it returns a newly-allocated |BIGNUM| on
422
+ // success instead, which the caller must release with |BN_free|.
423
+ OPENSSL_EXPORT BIGNUM * ASN1_INTEGER_to_BN (const ASN1_INTEGER * ai , BIGNUM * bn );
424
+
425
+ // ASN1_INTEGER_cmp compares the values of |x| and |y|. It returns an integer
426
+ // equal to, less than, or greater than zero if |x| is equal to, less than, or
427
+ // greater than |y|, respectively.
428
+ OPENSSL_EXPORT int ASN1_INTEGER_cmp (const ASN1_INTEGER * x ,
429
+ const ASN1_INTEGER * y );
430
+
431
+ // ASN1_ENUMERATED_set sets |a| to an ENUMERATED with value |v|. It returns one
432
+ // on success and zero on error.
433
+ OPENSSL_EXPORT int ASN1_ENUMERATED_set (ASN1_ENUMERATED * a , long v );
434
+
435
+ // ASN1_INTEGER_get returns the value of |a| as a |long|, or -1 if |a| is out of
436
+ // range or the wrong type.
437
+ OPENSSL_EXPORT long ASN1_ENUMERATED_get (const ASN1_ENUMERATED * a );
438
+
439
+ // BN_to_ASN1_ENUMERATED sets |ai| to an ENUMERATED with value |bn| and returns
440
+ // |ai| on success or NULL or error. If |ai| is NULL, it returns a
441
+ // newly-allocated |ASN1_INTEGER| on success instead, which the caller must
442
+ // release with |ASN1_INTEGER_free|.
443
+ OPENSSL_EXPORT ASN1_ENUMERATED * BN_to_ASN1_ENUMERATED (const BIGNUM * bn ,
444
+ ASN1_ENUMERATED * ai );
445
+
446
+ // ASN1_ENUMERATED_to_BN sets |bn| to the value of |ai| and returns |bn| on
447
+ // success or NULL or error. If |bn| is NULL, it returns a newly-allocated
448
+ // |BIGNUM| on success instead, which the caller must release with |BN_free|.
449
+ OPENSSL_EXPORT BIGNUM * ASN1_ENUMERATED_to_BN (const ASN1_ENUMERATED * ai ,
450
+ BIGNUM * bn );
451
+
452
+ // TODO(davidben): Expand and document function prototypes generated in macros.
453
+
454
+
390
455
391
456
// Arbitrary elements.
392
457
@@ -886,8 +951,6 @@ OPENSSL_EXPORT ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,
886
951
const unsigned char * * pp ,
887
952
long length );
888
953
OPENSSL_EXPORT ASN1_INTEGER * ASN1_INTEGER_dup (const ASN1_INTEGER * x );
889
- OPENSSL_EXPORT int ASN1_INTEGER_cmp (const ASN1_INTEGER * x ,
890
- const ASN1_INTEGER * y );
891
954
892
955
DECLARE_ASN1_FUNCTIONS (ASN1_ENUMERATED )
893
956
@@ -957,20 +1020,6 @@ OPENSSL_EXPORT ASN1_OBJECT *ASN1_OBJECT_create(int nid,
957
1020
int len , const char * sn ,
958
1021
const char * ln );
959
1022
960
- OPENSSL_EXPORT int ASN1_INTEGER_set (ASN1_INTEGER * a , long v );
961
- OPENSSL_EXPORT int ASN1_INTEGER_set_uint64 (ASN1_INTEGER * out , uint64_t v );
962
- OPENSSL_EXPORT long ASN1_INTEGER_get (const ASN1_INTEGER * a );
963
- OPENSSL_EXPORT ASN1_INTEGER * BN_to_ASN1_INTEGER (const BIGNUM * bn ,
964
- ASN1_INTEGER * ai );
965
- OPENSSL_EXPORT BIGNUM * ASN1_INTEGER_to_BN (const ASN1_INTEGER * ai , BIGNUM * bn );
966
-
967
- OPENSSL_EXPORT int ASN1_ENUMERATED_set (ASN1_ENUMERATED * a , long v );
968
- OPENSSL_EXPORT long ASN1_ENUMERATED_get (const ASN1_ENUMERATED * a );
969
- OPENSSL_EXPORT ASN1_ENUMERATED * BN_to_ASN1_ENUMERATED (const BIGNUM * bn ,
970
- ASN1_ENUMERATED * ai );
971
- OPENSSL_EXPORT BIGNUM * ASN1_ENUMERATED_to_BN (const ASN1_ENUMERATED * ai ,
972
- BIGNUM * bn );
973
-
974
1023
// General
975
1024
// given a string, return the correct type, max is the maximum length
976
1025
OPENSSL_EXPORT int ASN1_PRINTABLE_type (const unsigned char * s , int max );
0 commit comments