~ubuntu-branches/ubuntu/maverick/openssl/maverick

« back to all changes in this revision

Viewing changes to crypto/asn1/a_enum.c

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2005-12-13 21:37:42 UTC
  • mto: (11.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051213213742-d0ydaylf80l16bj1
Tags: upstream-0.9.8a
ImportĀ upstreamĀ versionĀ 0.9.8a

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
#include <stdio.h>
60
60
#include "cryptlib.h"
61
61
#include <openssl/asn1.h>
 
62
#include <openssl/bn.h>
62
63
 
63
64
/* 
64
65
 * Code for ENUMERATED type: identical to INTEGER apart from a different tag.
67
68
 
68
69
int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
69
70
        {
70
 
        int i,j,k;
 
71
        int j,k;
 
72
        unsigned int i;
71
73
        unsigned char buf[sizeof(long)+1];
72
74
        long d;
73
75
 
74
76
        a->type=V_ASN1_ENUMERATED;
75
 
        if (a->length < (sizeof(long)+1))
 
77
        if (a->length < (int)(sizeof(long)+1))
76
78
                {
77
79
                if (a->data != NULL)
78
80
                        OPENSSL_free(a->data);
116
118
        else if (i != V_ASN1_ENUMERATED)
117
119
                return -1;
118
120
        
119
 
        if (a->length > sizeof(long))
 
121
        if (a->length > (int)sizeof(long))
120
122
                {
121
123
                /* hmm... a bit ugly */
122
124
                return(0xffffffffL);
147
149
                ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
148
150
                goto err;
149
151
                }
150
 
        if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED;
 
152
        if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED;
151
153
        else ret->type=V_ASN1_ENUMERATED;
152
154
        j=BN_num_bits(bn);
153
155
        len=((j == 0)?0:((j/8)+1));
156
158
                unsigned char *new_data=OPENSSL_realloc(ret->data, len+4);
157
159
                if (!new_data)
158
160
                        {
159
 
                        ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
 
161
                        ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
160
162
                        goto err;
161
163
                        }
162
164
                ret->data=new_data;
175
177
 
176
178
        if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
177
179
                ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
178
 
        else if(ai->type == V_ASN1_NEG_ENUMERATED) ret->neg = 1;
 
180
        else if(ai->type == V_ASN1_NEG_ENUMERATED) BN_set_negative(ret,1);
179
181
        return(ret);
180
182
        }