Summary:ASTERISK-05769: [patch] BASE64_ENCODE and BASE64_DECODE
Reporter:Clod Patry (junky)Labels:
Date Opened:2005-12-02 23:46:35.000-0600Date Closed:2006-01-09 18:53:17.000-0600
Versions:Frequency of
Environment:Attachments:( 0) func_base64.c
Description:Since, we have function MD5(), i just created the base64 in both ways.


exten => 74,1,Set(encoded=${BASE64_ENCODE(oh yeah base64 via function in *)});
exten => 74,n,Set(decoded=${BASE64_DECODE(${encoded})});

will produce:
   -- Executing Set("SIP/20-da34", "encoded=b2ggeWVhaCBiYXNlNjQgdmlhIGZ1bmN0aW9uIGluICo") in new stack
   -- Executing Set("SIP/20-da34", "decoded=oh yeah base64 via function in *") in new stack

exten => 75,1,Set(encoded=${BASE64_ENCODE(foobar!@#$%^&*()1234567890)});
exten => 75,n,Set(decoded=${BASE64_DECODE(${encoded})});

will produce:
   -- Executing Set("SIP/20-ad33", "encoded=Zm9vYmFyIUAjJCVeJiooKTEyMzQ1Njc4OTA") in new stack
   -- Executing Set("SIP/20-ad33", "decoded=foobar!@#$%^&*()1234567890") in new stack
Comments:By: Tilghman Lesher (tilghman) 2005-12-03 00:22:33.000-0600

Why not size the output buffer dynamically?  Base64 does an 8 to 6 bit conversion, so strlen(input) * 4 / 3 + 1 should give an adequately sized buffer in all cases (just alloca() it).

For that matter, you already have an adequate buffer for the output in the parameter buf.  Why not just use buf directly?

By: Tilghman Lesher (tilghman) 2005-12-03 00:27:47.000-0600

Also, your .desc in _DECODE appears to be left over from another function.  The function returns a string, not a number.

By: Clod Patry (junky) 2005-12-03 16:03:56.000-0600

Corydon: thanks for suggestion for the buf and for finding the .desc text.
Both are fixed.

By: Russell Bryant (russell) 2005-12-04 20:59:52.000-0600

There are some formatting issues in the uploaded file:

1)  The entire file is double spaced.

2)  There should be spaces around the '=' in an assignment.  Example: int x = 0;

By: Clod Patry (junky) 2006-01-09 18:31:37.000-0600

Anything else here?

By: Matt O'Gorman (mogorman) 2006-01-09 18:53:00.000-0600

commited in trunk 7921 with minor white space changes and added to makefile