mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 01:48:00 +00:00
Move base64_decode_atom into misc.c.
I'm about to need to refer to it from a source file that won't necessarily always be linked against sshpubk.c, so it needs to live somewhere less specialist. Now it sits alongside base64_encode_atom (already in misc.c for another reason), which is neater anyway. [originally from svn r10218]
This commit is contained in:
parent
2e364812da
commit
80a9a7918a
51
misc.c
51
misc.c
@ -473,8 +473,7 @@ char *fgetline(FILE *fp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
* Base64 encoding routine. This is required in public-key writing
|
* Core base64 encoding and decoding routines.
|
||||||
* but also in HTTP proxy handling, so it's centralised here.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void base64_encode_atom(unsigned char *data, int n, char *out)
|
void base64_encode_atom(unsigned char *data, int n, char *out)
|
||||||
@ -501,6 +500,54 @@ void base64_encode_atom(unsigned char *data, int n, char *out)
|
|||||||
out[3] = '=';
|
out[3] = '=';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int base64_decode_atom(char *atom, unsigned char *out)
|
||||||
|
{
|
||||||
|
int vals[4];
|
||||||
|
int i, v, len;
|
||||||
|
unsigned word;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
c = atom[i];
|
||||||
|
if (c >= 'A' && c <= 'Z')
|
||||||
|
v = c - 'A';
|
||||||
|
else if (c >= 'a' && c <= 'z')
|
||||||
|
v = c - 'a' + 26;
|
||||||
|
else if (c >= '0' && c <= '9')
|
||||||
|
v = c - '0' + 52;
|
||||||
|
else if (c == '+')
|
||||||
|
v = 62;
|
||||||
|
else if (c == '/')
|
||||||
|
v = 63;
|
||||||
|
else if (c == '=')
|
||||||
|
v = -1;
|
||||||
|
else
|
||||||
|
return 0; /* invalid atom */
|
||||||
|
vals[i] = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vals[0] == -1 || vals[1] == -1)
|
||||||
|
return 0;
|
||||||
|
if (vals[2] == -1 && vals[3] != -1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (vals[3] != -1)
|
||||||
|
len = 3;
|
||||||
|
else if (vals[2] != -1)
|
||||||
|
len = 2;
|
||||||
|
else
|
||||||
|
len = 1;
|
||||||
|
|
||||||
|
word = ((vals[0] << 18) |
|
||||||
|
(vals[1] << 12) | ((vals[2] & 0x3F) << 6) | (vals[3] & 0x3F));
|
||||||
|
out[0] = (word >> 16) & 0xFF;
|
||||||
|
if (len > 1)
|
||||||
|
out[1] = (word >> 8) & 0xFF;
|
||||||
|
if (len > 2)
|
||||||
|
out[2] = word & 0xFF;
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
* Generic routines to deal with send buffers: a linked list of
|
* Generic routines to deal with send buffers: a linked list of
|
||||||
* smallish blocks, with the operations
|
* smallish blocks, with the operations
|
||||||
|
1
misc.h
1
misc.h
@ -44,6 +44,7 @@ int toint(unsigned);
|
|||||||
char *fgetline(FILE *fp);
|
char *fgetline(FILE *fp);
|
||||||
|
|
||||||
void base64_encode_atom(unsigned char *data, int n, char *out);
|
void base64_encode_atom(unsigned char *data, int n, char *out);
|
||||||
|
int base64_decode_atom(char *atom, unsigned char *out);
|
||||||
|
|
||||||
struct bufchain_granule;
|
struct bufchain_granule;
|
||||||
typedef struct bufchain_tag {
|
typedef struct bufchain_tag {
|
||||||
|
48
sshpubk.c
48
sshpubk.c
@ -513,54 +513,6 @@ static char *read_body(FILE * fp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int base64_decode_atom(char *atom, unsigned char *out)
|
|
||||||
{
|
|
||||||
int vals[4];
|
|
||||||
int i, v, len;
|
|
||||||
unsigned word;
|
|
||||||
char c;
|
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
|
||||||
c = atom[i];
|
|
||||||
if (c >= 'A' && c <= 'Z')
|
|
||||||
v = c - 'A';
|
|
||||||
else if (c >= 'a' && c <= 'z')
|
|
||||||
v = c - 'a' + 26;
|
|
||||||
else if (c >= '0' && c <= '9')
|
|
||||||
v = c - '0' + 52;
|
|
||||||
else if (c == '+')
|
|
||||||
v = 62;
|
|
||||||
else if (c == '/')
|
|
||||||
v = 63;
|
|
||||||
else if (c == '=')
|
|
||||||
v = -1;
|
|
||||||
else
|
|
||||||
return 0; /* invalid atom */
|
|
||||||
vals[i] = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vals[0] == -1 || vals[1] == -1)
|
|
||||||
return 0;
|
|
||||||
if (vals[2] == -1 && vals[3] != -1)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (vals[3] != -1)
|
|
||||||
len = 3;
|
|
||||||
else if (vals[2] != -1)
|
|
||||||
len = 2;
|
|
||||||
else
|
|
||||||
len = 1;
|
|
||||||
|
|
||||||
word = ((vals[0] << 18) |
|
|
||||||
(vals[1] << 12) | ((vals[2] & 0x3F) << 6) | (vals[3] & 0x3F));
|
|
||||||
out[0] = (word >> 16) & 0xFF;
|
|
||||||
if (len > 1)
|
|
||||||
out[1] = (word >> 8) & 0xFF;
|
|
||||||
if (len > 2)
|
|
||||||
out[2] = word & 0xFF;
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned char *read_blob(FILE * fp, int nlines, int *bloblen)
|
static unsigned char *read_blob(FILE * fp, int nlines, int *bloblen)
|
||||||
{
|
{
|
||||||
unsigned char *blob;
|
unsigned char *blob;
|
||||||
|
Loading…
Reference in New Issue
Block a user