]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
(base64_encode): Broke out some common code from the switch..
authorNiels Möller <nisse@lysator.liu.se>
Mon, 30 Sep 2002 19:39:23 +0000 (21:39 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Mon, 30 Sep 2002 19:39:23 +0000 (21:39 +0200)
Rev: src/nettle/base64.c:1.4

base64.c

index 7124060e9236707f7fc22ec400e3fe0a6e8776fe..566cd30b10e291610c001a39ad1aea786e127dfb 100644 (file)
--- a/base64.c
+++ b/base64.c
@@ -71,27 +71,24 @@ base64_encode(uint8_t *dst,
 
   if (left_over)
     {
+      in -= left_over;
+      *--out = '=';
       switch(left_over)
        {
        case 1:
-         in--;
-         *--out = '=';
          *--out = '=';
          *--out = ENCODE(in[0] << 4);
-         *--out = ENCODE(in[0] >> 2);
          break;
          
        case 2:
-         in-= 2;
-         *--out = '=';
          *--out = ENCODE( in[1] << 2);
          *--out = ENCODE((in[0] << 4) | (in[1] >> 4));
-         *--out = ENCODE( in[0] >> 2);
          break;
 
        default:
          abort();
        }
+      *--out = ENCODE(in[0] >> 2);
     }
   
   while (in > src)