~vcs-imports/putty/trunk

« back to all changes in this revision

Viewing changes to sshpubk.c

  • Committer: simon
  • Date: 2014-09-09 11:46:10 UTC
  • Revision ID: svn-v4:cda61777-01e9-0310-a592-d414129be87e:putty:10218
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
513
513
    }
514
514
}
515
515
 
516
 
int base64_decode_atom(char *atom, unsigned char *out)
517
 
{
518
 
    int vals[4];
519
 
    int i, v, len;
520
 
    unsigned word;
521
 
    char c;
522
 
 
523
 
    for (i = 0; i < 4; i++) {
524
 
        c = atom[i];
525
 
        if (c >= 'A' && c <= 'Z')
526
 
            v = c - 'A';
527
 
        else if (c >= 'a' && c <= 'z')
528
 
            v = c - 'a' + 26;
529
 
        else if (c >= '0' && c <= '9')
530
 
            v = c - '0' + 52;
531
 
        else if (c == '+')
532
 
            v = 62;
533
 
        else if (c == '/')
534
 
            v = 63;
535
 
        else if (c == '=')
536
 
            v = -1;
537
 
        else
538
 
            return 0;                  /* invalid atom */
539
 
        vals[i] = v;
540
 
    }
541
 
 
542
 
    if (vals[0] == -1 || vals[1] == -1)
543
 
        return 0;
544
 
    if (vals[2] == -1 && vals[3] != -1)
545
 
        return 0;
546
 
 
547
 
    if (vals[3] != -1)
548
 
        len = 3;
549
 
    else if (vals[2] != -1)
550
 
        len = 2;
551
 
    else
552
 
        len = 1;
553
 
 
554
 
    word = ((vals[0] << 18) |
555
 
            (vals[1] << 12) | ((vals[2] & 0x3F) << 6) | (vals[3] & 0x3F));
556
 
    out[0] = (word >> 16) & 0xFF;
557
 
    if (len > 1)
558
 
        out[1] = (word >> 8) & 0xFF;
559
 
    if (len > 2)
560
 
        out[2] = word & 0xFF;
561
 
    return len;
562
 
}
563
 
 
564
516
static unsigned char *read_blob(FILE * fp, int nlines, int *bloblen)
565
517
{
566
518
    unsigned char *blob;