ASN1_STRING_cmp() -- SSLeay 0.9.0b -- January 1999

NAME

ASN1_STRING_cmp, ASN1_STRING_set, ASN1_STRING_dup, ASN1_STRING_print,
ASN1_BIT_STRING_set_bit, ASN1_BIT_STRING_get_bit, i2a_ASN1_STRING,
a2i_ASN1_STRING -- ASN1_STRING manipulation routines

SYNOPSIS

#include "asn1.h"

int ASN1_STRING_cmp(a, b)
ASN1_STRING *a, *b;

int ASN1_STRING_set(str, data, len)
ASN1_STRING *str;
unsigned char *data; int len;

ASN1_STRING *ASN1_STRING_dup(a)
ASN1_STRING *a;

int ASN1_STRING_print(bp, v)
BIO *bp; ASN1_STRING *v;

int ASN1_BIT_STRING_set_bit(a, n, value)
ASN1_BIT_STRING *a;
int n;
int value;

int ASN1_BIT_STRING_get_bit(a, n)
ASN1_BIT_STRING *a;
int n;

int i2a_ASN1_STRING(bp, a, type)
BIO *bp;
ASN1_STRING *a;
int type;

int a2i_ASN1_STRING(bp, bs, buf, size)
BIO *bp;
ASN1_STRING *bs;
char *buf;
int size;

DESCRIPTION

These functions all operate on ASN1_STRING structures; see ASN1 types and structures for a definition of this structure.

ASN1_STRING_cmp compares the ASN1_STRING structures pointed to by a and b; if they are equal (same length, same content byte by byte, same type) 0 is returned, else an integer less than zero or greater than zero is returned depending on whether the length, content, or type of a is less than or greater than b, tested in that order. This means that the contents may be the same but you could get a non-zero number because the types don't match. Here, type is one of

V_ASN1_BIT_STRING V_ASN1_BMPSTRING V_ASN1_GENERALIZEDTIME V_ASN1_GENERALSTRING V_ASN1_IA5STRING V_ASN1_INTEGER V_ASN1_OCTET_STRING V_ASN1_PRINTABLESTRING V_ASN1_T61STRING V_ASN1_UNIVERSALSTRING V_ASN1_UTCTIME

ASN1_STRING_set uses the ASN1_STRING structure pointed to by str, puts the len bytes pointed to by data into the data element of the structure, copies len into the length element of the structure, and puts a trailng '\0' at the end (isn't that nice?) If str>data is initially NULL, space will be allocated for that subfield so that data can be copied into it. It returns 1 on success. If str is NULL or there is an error, 0 is returned.

ASN1_STRING_dup returns a pointer to a copy of the ASN1_STRING structure pointed to by a. If a is NULL or if there is an error, NULL is returned.

ASN1_STRING_print prints to the BIO pointed to by bp the contents of the ASN1_STRING v, as a character string, with unprintable (control or 8-bit) characters represented by '.'

It returns 1 on success and 0 on error.

ASN1_BIT_STRING_set_bit sets the nth bit in a->data where the bits in a given byte are ordered from msb=(bytenum*8)+0 to lsb=(bytenum*8)+7. If value is not set, then this fnction does nothing (so it won't clear a bit for you).

If a->data isn't long enough to set the bit you want to set, it will be alloced or realloced for you. However, it is not the case that all new bytes alloced will be automatically initialized to 0 (or any other good value) for you; only the particular byte affected will be cleared and then the appropriate bit set. For this reason you should take care to make sure that a->data is already long enough. 1 is returned on success, or 0 on error.

ASN1_BIT_STRING_get_bit returns the value of the bit n in a->data, counting the same way as in ASN1_BIT_STRING_set_bit above. If a->data is NULL or not long enough to contain n bits, 0 is returned.

The following macros are provided for the convenience of the user:

#define ASN1_STRING_length(x)    ((x)->length)
#define ASN1_STRING_type(x)      ((x)->type)
#define ASN1_STRING_data(x)      ((x)->data)

#define ASN1_BIT_STRING_dup(a) 
  (ASN1_BIT_STRING *) ASN1_STRING_dup((ASN1_STRING *)a)
#define ASN1_BIT_STRING_cmp(a,b) 
  ASN1_STRING_cmp((ASN1_STRING *)a,(ASN1_STRING *)b)
#define ASN1_BIT_STRING_set(a,b,c) 
  ASN1_STRING_set((ASN1_STRING *)a,b,c)
#define ASN1_OCTET_STRING_dup(a) 
  (ASN1_OCTET_STRING *) ASN1_STRING_dup((ASN1_STRING *)a)
#define ASN1_OCTET_STRING_cmp(a,b) 
  ASN1_STRING_cmp((ASN1_STRING *)a,(ASN1_STRING *)b)
#define ASN1_OCTET_STRING_set(a,b,c)
  ASN1_STRING_set((ASN1_STRING *)a,b,c)

i2a_ASN1_STRING() writes out to BIO output file bp the data element of the ASN1_STRING that a points to, hexadecimal notation, breaking up the string into lines of 70 characters each and a continuation marker '\' at the end of each line, if the string is that long.

If a is NULL then this function does nothing and 0 is returned; if the length of the data a points to is 0, then the value '0' is written and 1 is returned.

Upon success, this function returns the number of bytes written; on error, it returns -1.

a2i_ASN1_STRING() reads from the BIO input file bp a string which has been written in hexadecimal notation with '\' as a continuation marker if the integer spans more than one line. It then stores the string in the ASN1_STRING structure bs. buf is the buffer used in conjunction with the bp file pointer and size is the size of the buffer (see the documentation on BIO files and operations for more information).

Upon success, it returns 1, and on error, 0.