How safe is this?

Ron Teitelbaum Ron at USMedRec.com
Tue Jun 6 20:02:15 UTC 2006


Chris and All,

I was looking at ByteArray>>uint:at: and ByteArray>>uint:at:put: and from
what I'm seeing this is basically a way to add an int into a byteArray at a
given position?  

My 256 bit integer storage was 

(ByteArray new: 32)uint: 256 at: 1 put: myInt and to get it back was
aByteArray unit: 256 at: 1.

Was there more to this then that?  One of the neat things I saw was
aByteArray, aByteArray  and aByteArray, 'abc' worked!

I had started using XML for context, and ran into serious problems with the
converted strings esp. when a byte of my number resulted in $< so binary is
definitely the way to go.

The issue now is that I'd like to have dynamic context retaining some of the
benefits of XML.  

I've done ncpdp transactions where header info is encoded <special header
character>A36<special header character>36 bytes of alpha header
information<special body segment character><field separator character>field
id<field separator character>data ....

Is this the best way to do mixed alpha and binary or can anyone suggest
better ways to pass context info, for example like in headers or to map XML
like structures to Binary or a way to detect and translate what is a string
and what is a number in a byteArray?

My goal here is to maximize storage and transfer speed, I learned my lesson
in my last system where we encoded UUID's as characters, and you wouldn't
think it but they used up a huge amount of room on Oracle, and consumed a
very large amount of network traffic.  

Thanks for your help!

Ron Teitelbaum
President / Principal Software Engineer
US Medical Record Specialists
Ron at USMedRec.com  


> From: Chris Muller
> Sent: Monday, June 05, 2006 4:03 PM
> 
> Hi Ron, as long as your parsing is perfect, I think this conversion
> would be fine and platform independent.  I would be sure to test your
> code works on numbers that do not have the high order bit set, since
> this would result in a shorter-length of the represented number.  Niels
> Ferguson and Bruce Schneier suggest using little-endian representations
> of control fields in a secure-channel which is why, personally, I use
> ByteArray>>#uint:at: and #uint:at:put: now provided by Cryptography.
> 
> As you know using Strings does introduce the potential for platform
> dependencies; have you considered simply stopping at the ByteArray and
> using binary?
> 
>   yourNumber asByteArray asInteger = yourNumber
> 
> Regards,
>   Chris
> --- Ron Teitelbaum <Ron at USMedRec.com> wrote:
> 
> > Hello all,
> > Can you tell me if this is safe for all platforms?
> > self asByteArray asString asByteArray asInteger = self   ->   true
> > I have a largePositiveInteger that needs to be sent on the wire.  I'm
> > trying
> > to convert to save space the number is 256 bits.
> > The resulting string which is going out is 32bytes which seems to me
> > to be
> > the best that can be done storage wise, will I have any trouble on
> > different
> > platforms when I grab the string and do asByteArray asInteger?
> > Is there a better way to store the number?
> > Thanks,





More information about the Squeak-dev mailing list