comparison libtomcrypt/src/pk/asn1/der/ia5/der_encode_ia5_string.c @ 382:0cbe8f6dbf9e

propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 2af22fb4e878750b88f80f90d439b316d229796f) to branch 'au.asn.ucc.matt.dropbear' (head 02c413252c90e9de8e03d91e9939dde3029f5c0a)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:41:05 +0000
parents 1b9e69c058d2
children f849a5ca2efc
comparison
equal deleted inserted replaced
379:b66a00272a90 382:0cbe8f6dbf9e
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 * 8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org 9 * Tom St Denis, [email protected], http://libtomcrypt.com
10 */ 10 */
11 #include "tomcrypt.h" 11 #include "tomcrypt.h"
12 12
13 /** 13 /**
14 @file der_encode_ia5_string.c 14 @file der_encode_ia5_string.c
40 return err; 40 return err;
41 } 41 }
42 42
43 /* too big? */ 43 /* too big? */
44 if (len > *outlen) { 44 if (len > *outlen) {
45 *outlen = len;
45 return CRYPT_BUFFER_OVERFLOW; 46 return CRYPT_BUFFER_OVERFLOW;
46 } 47 }
47 48
48 /* encode the header+len */ 49 /* encode the header+len */
49 x = 0; 50 x = 0;
50 out[x++] = 0x16; 51 out[x++] = 0x16;
51 if (inlen < 128) { 52 if (inlen < 128) {
52 out[x++] = inlen; 53 out[x++] = (unsigned char)inlen;
53 } else if (inlen < 256) { 54 } else if (inlen < 256) {
54 out[x++] = 0x81; 55 out[x++] = 0x81;
55 out[x++] = inlen; 56 out[x++] = (unsigned char)inlen;
56 } else if (inlen < 65536UL) { 57 } else if (inlen < 65536UL) {
57 out[x++] = 0x82; 58 out[x++] = 0x82;
58 out[x++] = (inlen>>8)&255; 59 out[x++] = (unsigned char)((inlen>>8)&255);
59 out[x++] = inlen&255; 60 out[x++] = (unsigned char)(inlen&255);
60 } else if (inlen < 16777216UL) { 61 } else if (inlen < 16777216UL) {
61 out[x++] = 0x83; 62 out[x++] = 0x83;
62 out[x++] = (inlen>>16)&255; 63 out[x++] = (unsigned char)((inlen>>16)&255);
63 out[x++] = (inlen>>8)&255; 64 out[x++] = (unsigned char)((inlen>>8)&255);
64 out[x++] = inlen&255; 65 out[x++] = (unsigned char)(inlen&255);
65 } else { 66 } else {
66 return CRYPT_INVALID_ARG; 67 return CRYPT_INVALID_ARG;
67 } 68 }
68 69
69 /* store octets */ 70 /* store octets */
78 } 79 }
79 80
80 #endif 81 #endif
81 82
82 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/ia5/der_encode_ia5_string.c,v $ */ 83 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/ia5/der_encode_ia5_string.c,v $ */
83 /* $Revision: 1.1 $ */ 84 /* $Revision: 1.4 $ */
84 /* $Date: 2005/05/16 15:08:11 $ */ 85 /* $Date: 2006/12/04 21:34:03 $ */