From: "MartinBosslet (Martin Bosslet)" Date: 2012-04-30T11:35:35+09:00 Subject: [ruby-core:44763] [ruby-trunk - Feature #6361] Bitwise string operations Issue #6361 has been updated by MartinBosslet (Martin Bosslet). File bytestring001.tar.gz added > If I may intrude for a moment��� No such thing - thank you for your ideas! >I think the advantage to having a built in Data/Blob library would be that it could be used in all places where a data class is more appropriate than a string. For example, the Socket library currently returns Strings for data read in from a socket. I think a Data class is more appropriate here since the socket itself does not contain encoding information (i.e. either an arbitrary default encoding needs to be set, a heuristic can be used to guess the encoding, or the encoding is set by a previously agreed up convention; but you cannot ask a socket for its encoding). That's a good point. IO would definitely benefit from this feature, Strings would only be needed when reading line by line. Encoding would not be a problem anymore when reading raw bytes. > A quick attempt at a spec: I picked up Joshua's ideas and implemented a fully functional ByteString class (simulating the desired behavior in Ruby for now). I like ByteString better than Data, but that's me, I would be fine with whatever name the majority likes best. The class features a reduced String interface like Joshua proposed already, plus bit-level operations and a #to_hex/from_hex (I need those all the time). In addition, there is ByteString::Immutable, which tries to illustrate the behavior I had in mind for a class that would allow secure in-memory erasure of its contents. It can only be created from an IO directly (we can't use a String because this would already leak the sensitive information). By default, ByteString copies the contents it is given, but if we want to include referencing as described by Joshua, this could be integrated in Immutable, and the security aspects could be implemented in yet another class, that borrows most of its functionality from Immutable. To demonstrate the behavior and as a basis for further discussion, I included specs for both classes, I find those to be the easiest way for discussing an interface. The code can also be found at [1], in case somebody would like to hack on it and improve it, I would update this thread in that case. [1] https://github.com/emboss/bytestring ---------------------------------------- Feature #6361: Bitwise string operations https://bugs.ruby-lang.org/issues/6361#change-26323 Author: MartinBosslet (Martin Bosslet) Status: Feedback Priority: Normal Assignee: Category: core Target version: I know this has been discussed a lot in the past (and if there's still an open issue for this, I apologize, I couldn't find one), for example in [1]. While it is generally no problem to implement this on the fly, I still find that built-in support would be a real improvement. There are quite some use cases in cryptography where this would come in very handy, but I'm sure there are lots of other areas, too. While of course I understand the reasons that were given in the previous threads that ultimately lead to rejection, I still would like to reopen the discussion as I felt that in every thread so far the consensus was that having bitwise string operations would indeed be quite valuable. [1] http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/34586 -- http://bugs.ruby-lang.org/