Natools

Diff
Login

Differences From Artifact [55ec865df9]:

To Artifact [6be873c8b5]:


327
328
329
330
331
332
333
334
335
336
337



































































338
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405











+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

            Encode_Base64
              (Result (Cursor .. Cursor + 3),
               Data (I));
            I := I + 1;
         end if;
         Cursor := Cursor + 4;
      end loop;

      return Result;
   end Encode_Base64;



   ---------------------------------
   -- Base-64 with other charsets --
   ---------------------------------

   function Decode_Base64 (Data : in Atom; Digit_62, Digit_63 : in Octet)
     return Atom
   is
      Recoded : Atom := Data;
   begin
      for I in Recoded'Range loop
         if Recoded (I) = Digit_62 then
            Recoded (I) := Plus;
         elsif Recoded (I) = Digit_63 then
            Recoded (I) := Slash;
         end if;
      end loop;

      return Decode_Base64 (Recoded);
   end Decode_Base64;


   function Encode_Base64 (Data : in Atom; Digit_62, Digit_63 : in Octet)
     return Atom
   is
      Result : Atom := Encode_Base64 (Data);
      Last : Count := Result'Last;
   begin
      for I in Result'Range loop
         if Result (I) = Plus then
            Result (I) := Digit_62;
         elsif Result (I) = Slash then
            Result (I) := Digit_63;
         elsif Result (I) = Base64_Filler then
            for J in I + 1 .. Result'Last loop
               pragma Assert (Result (J) = Base64_Filler);
            end loop;
            Last := I - 1;
            exit;
         end if;
      end loop;

      return Result (Result'First .. Last);
   end Encode_Base64;


   function Encode_Base64
     (Data : in Atom;
      Digit_62, Digit_63, Padding : in Octet)
     return Atom
   is
      Result : Atom := Encode_Base64 (Data);
   begin
      for I in Result'Range loop
         if Result (I) = Plus then
            Result (I) := Digit_62;
         elsif Result (I) = Slash then
            Result (I) := Digit_63;
         elsif Result (I) = Base64_Filler then
            Result (I) := Padding;
         end if;
      end loop;

      return Result;
   end Encode_Base64;

end Natools.S_Expressions.Encodings;