comparison libtomcrypt/src/pk/asn1/der/printable_string/der_encode_printable_string.c @ 478:d4f32c3443ac dbclient-netcat-alike

propagate from branch 'au.asn.ucc.matt.dropbear' (head f21045c791002d81fc6b8dde6537ea481e513eb2) to branch 'au.asn.ucc.matt.dropbear.dbclient-netcat-alike' (head d1f69334581dc4c35f9ca16aa5355074c9dd315d)
author Matt Johnston <matt@ucc.asn.au>
date Sun, 14 Sep 2008 06:47:51 +0000
parents 0cbe8f6dbf9e
children f849a5ca2efc
comparison
equal deleted inserted replaced
296:6b41e2cbf071 478:d4f32c3443ac
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_printable_string.c 14 @file der_encode_printable_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++] = 0x13; 51 out[x++] = 0x13;
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/printable_string/der_encode_printable_string.c,v $ */ 83 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/printable_string/der_encode_printable_string.c,v $ */
83 /* $Revision: 1.1 $ */ 84 /* $Revision: 1.4 $ */
84 /* $Date: 2005/05/21 02:29:54 $ */ 85 /* $Date: 2006/12/04 21:34:03 $ */