Skip to content

Commit 46bc615

Browse files
committed
CHANGE: enbase using line breaks by default; new enbase/flat for old behavior.
Also molded binary now does not add a line break before closing bracket!
1 parent 7644bee commit 46bc615

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

src/boot/natives.reb

+1
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ enbase: native [
406406
/url {Base 64 Encoding with URL and Filename Safe Alphabet}
407407
/part {Limit the length of the input}
408408
limit [integer! binary! any-string!]
409+
/flat {Base 64 Encoding without line breaks}
409410
]
410411

411412
decloak: native [

src/core/f-enbase.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ static REBU64 base36_powers[BASE36_LENGTH] = {
891891
}
892892
*p = 0;
893893

894-
if (*(p-1) != LF && len > 9 && brk) *p++ = LF;
894+
//if (*(p-1) != LF && len > 9 && brk) *p++ = LF; // adds LF before closing bracket
895895

896896
SERIES_TAIL(series) = DIFF_PTRS(p, series->data);
897897
return series;
@@ -923,7 +923,7 @@ static REBU64 base36_powers[BASE36_LENGTH] = {
923923
if (brk && ((count % 32) == 0)) *bp++ = LF;
924924
}
925925

926-
if ((len >= 32) && brk && *(bp-1) != LF) *bp++ = LF;
926+
//if ((len >= 32) && brk && *(bp-1) != LF) *bp++ = LF; // adds LF before closing bracket
927927
*bp = 0;
928928

929929
SERIES_TAIL(series) = DIFF_PTRS(bp, series->data);
@@ -980,7 +980,7 @@ static REBU64 base36_powers[BASE36_LENGTH] = {
980980
p++;
981981
}
982982

983-
if (*(p-1) != LF && x > 49 && brk) *p++ = LF;
983+
//if (*(p-1) != LF && x > 49 && brk) *p++ = LF; // adds LF before closing bracket
984984
*p = 0;
985985

986986
SERIES_TAIL(series) = DIFF_PTRS(p, series->data); /* 4 * (int) (len % 3 ? (len / 3) + 1 : len / 3); */

src/core/n-strings.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ static struct digest {
515515
REBINT base = VAL_INT32(D_ARG(2));
516516
REBCNT limit = NO_LIMIT;
517517
REBVAL *part = D_ARG(5);
518+
REBOOL brk = !D_REF(6);
518519

519520
if (D_REF(4)) {
520521
limit = Partial(arg, 0, part, 0); // Can modify value index.
@@ -529,13 +530,13 @@ static struct digest {
529530

530531
switch (base) {
531532
case 64:
532-
ser = Encode_Base64(arg, 0, limit, FALSE, D_REF(3));
533+
ser = Encode_Base64(arg, 0, limit, brk, D_REF(3));
533534
break;
534535
case 16:
535-
ser = Encode_Base16(arg, 0, limit, FALSE);
536+
ser = Encode_Base16(arg, 0, limit, brk);
536537
break;
537538
case 2:
538-
ser = Encode_Base2(arg, 0, limit, FALSE);
539+
ser = Encode_Base2(arg, 0, limit, brk);
539540
break;
540541
case 85:
541542
#ifdef INCLUDE_BASE85

src/mezz/prot-smtp.reb

+4-4
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ sync-smtp-handler: function [event][
196196
smtp-port/state: 'PLAIN
197197
write client to binary! ajoin [
198198
"AUTH PLAIN "
199-
enbase ajoin [spec/user #"^@" spec/user #"^@" spec/pass] 64
199+
enbase/flat ajoin [spec/user #"^@" spec/user #"^@" spec/pass] 64
200200
CRLF
201201
]
202202
return false
@@ -232,12 +232,12 @@ sync-smtp-handler: function [event][
232232
find/part response "334 VXNlcm5hbWU6" 16 [ ;enbased "Username:"
233233
; username being requested
234234
sys/log/more 'SMTP "Client: ***user-name***"
235-
write client to binary! ajoin [enbase spec/user 64 CRLF]
235+
write client to binary! ajoin [enbase/flat spec/user 64 CRLF]
236236
]
237237
find/part response "334 UGFzc3dvcmQ6" 16 [ ;enbased "Password:"
238238
; pass being requested
239239
sys/log/more 'SMTP "Client: ***user-pass***"
240-
write client to binary! ajoin [enbase spec/pass 64 CRLF]
240+
write client to binary! ajoin [enbase/flat spec/pass 64 CRLF]
241241
smtp-port/state: 'PASSWORD
242242
]
243243
true [
@@ -252,7 +252,7 @@ sync-smtp-handler: function [event][
252252
; compute challenge response
253253
auth-key: checksum/with auth-key 'md5 spec/pass
254254
sys/log/more 'SMTP "Client: ***auth-key***"
255-
write client to binary! ajoin [enbase ajoin [spec/user #" " lowercase enbase auth-key 16] 64 CRLF]
255+
write client to binary! ajoin [enbase/flat ajoin [spec/user #" " lowercase enbase auth-key 16] 64 CRLF]
256256
smtp-port/state: 'PASSWORD
257257
false
258258
][

src/tests/units/enbase-test.r3

+28
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,34 @@ Rebol [
3535
--test-- "enbase-64" --assert #{00FF00} = debase enbase next bin 64 64
3636
===end-group===
3737

38+
===start-group=== "enbase/flat"
39+
bin: read/binary %units/files/rbgw.gif
40+
--test-- "enbase/flat 2"
41+
--assert (enbase bin 2) == {
42+
0100011101001001010001100011100000110111011000010000001000000000
43+
0000001000000000111100100000000000000000110010000000000000000000
44+
0000000000000000110010000000000011001000000000001111111111111111
45+
1111111100100110010001011100100100100110010001011100100100100110
46+
0100010111001001001001100100010111001001001000011111100100000100
47+
0000000100000000000000000000010000000000001011000000000000000000
48+
0000000000000000000000100000000000000010000000000000000000000011
49+
000000110000100000100001100100110000000000111011}
50+
--assert (enbase/flat bin 2) == {0100011101001001010001100011100000110111011000010000001000000000000000100000000011110010000000000000000011001000000000000000000000000000000000001100100000000000110010000000000011111111111111111111111100100110010001011100100100100110010001011100100100100110010001011100100100100110010001011100100100100001111110010000010000000001000000000000000000000100000000000010110000000000000000000000000000000000000000100000000000000010000000000000000000000011000000110000100000100001100100110000000000111011}
51+
52+
--test-- "enbase/flat 16"
53+
--assert (enbase bin 16) == {
54+
47494638376102000200F20000C800000000C800C800FFFFFF2645C92645C926
55+
45C92645C921F90401000004002C0000000002000200000303082193003B}
56+
--assert (enbase/flat bin 16) == {47494638376102000200F20000C800000000C800C800FFFFFF2645C92645C92645C92645C921F90401000004002C0000000002000200000303082193003B}
57+
58+
--test-- "enbase/flat 64"
59+
--assert (enbase bin 64) == {
60+
R0lGODdhAgACAPIAAMgAAAAAyADIAP///yZFySZFySZFySZFySH5BAEAAAQALAAA
61+
AAACAAIAAAMDCCGTADs=}
62+
--assert (enbase/flat bin 64) == {R0lGODdhAgACAPIAAMgAAAAAyADIAP///yZFySZFySZFySZFySH5BAEAAAQALAAAAAACAAIAAAMDCCGTADs=}
63+
64+
===end-group===
65+
3866
===start-group=== "debase 64"
3967
--test-- "debase 64 1"
4068
--assert strict-equal? "A simple string" to string! debase "QSBzaW1wbGUgc3RyaW5n" 64

0 commit comments

Comments
 (0)