newLISP Fan Club

Forum => newLISP newS => Topic started by: cormullion on October 05, 2006, 02:59:33 PM

Title: string/append and base64
Post by: cormullion on October 05, 2006, 02:59:33 PM
Not sure what I'm doing, but I don't understand why these two give different results:


(println (append "AUTH PLAIN " (base64-enc (append "00" "user.name" "00" "password"))))
(println (append "AUTH PLAIN " (base64-enc (string "00" "user.name" "00" "password"))))

AUTH PLAIN AHVzZXIubmFtZQBwYXNzd29yZA==
AUTH PLAIN dXNlci5uYW1lcGFzc3dvcmQ=


I'm adapting SMTP.lsp to do authorization, but why should string be different? Is it a Unicode thing?
Title:
Post by: Lutz on October 05, 2006, 05:52:47 PM
'append' works on binary (non displayable ASCII). 'string' does not, it will take a 00 as a string terminator, like 'print' and 'println' which are based on 'string':


> (string "00")
""
> (append "00")
"00"
>


Lutz



ps: see docs for 'append' and 'string'. Do we need a chapter/paragraph explaining this, perhaps in

http://newlisp.org/downloads/newlisp_manual.html#type_ids ?
Title:
Post by: cormullion on October 06, 2006, 12:54:27 AM
Thanks, Lutz. I remember now. I was confusing myself partly by working in a file rather than directly in the terminal. I was trying to decode a string:


(set 's (base64-dec "AHVzZXIubmFtZQBwYXNzd29yZA=="))
(println s)


- of course println returns the value correctly ("00user.name00password") but it doesn't display anything.



For some reason, the AUTH part of SMTP uses these zero terminators so I got myself well confused...



What's a good way of displaying the contents of strings like this in a log file?
Title:
Post by: Lutz on October 06, 2006, 04:34:21 AM
Use plain 'replace' without the regular expressions option:


(replace "00" (base64-dec "AHVzZXIubmFtZQBwYXNzd29yZA==") " ")
=> " user.name password"


to change the "00" to a space or some other character.



Lutz
Title:
Post by: cormullion on October 06, 2006, 06:49:48 AM
Thanks! In fact. I'll replace it with "\000" just so that I know what's happening...