Passing a ubyte[] to a function taking a 'ref ubyte[16]'

Regan Heath regan at netmail.co.nz
Mon Jun 25 05:41:03 PDT 2012


On Sun, 24 Jun 2012 08:27:00 +0100, Johannes Pfau <nospam at example.com>  
wrote:

> Am Sat, 23 Jun 2012 16:51:14 -0700
> schrieb Jonathan M Davis <jmdavisProg at gmx.com>:
>
>> On Saturday, June 23, 2012 20:23:26 Johannes Pfau wrote:
>> > I'm working on the new design for std.hash and I hit an interesting
>> > problem:
>> >
>> > The OOP interface has to take buffers as slices with unknown
>> > length, as the length differs between hashes and I have to put a
>> > common function declaration in a interface. So I have this:
>> > ------------
>> > interface Digest
>> > {
>> >     ubyte[] finish(ubyte[] buf);
>> > }
>> > ------------
>>
>> I confess that I'm baffled as to why you'd even be using interfaces
>> for this, given that Phobos always uses structs and templates for
>> this sort of thing.
>
> As discussed in the main newsgroup I use both. Interfaces and classes
> are useful if you want to change the crypto backend (D/OpenSSL/Windows
> Crypto API) at runtime and without breaking the ABI. Regan Heath who
> designed the Tango digest module, also said that digets are often used
> with the factory pattern, which doesn't work with structs / templates.

Correction; I supplied some code which became the Tango digest modules,  
someone else defined the final API and made all my code 'fit'.  I think  
factory pattern is a commonly desired usage pattern for hashing, crypto,  
compression, etc.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d-learn mailing list