Re: [PROPOSAL] Crypto extension

From: Date: Tue, 17 Dec 2013 10:40:42 +0000
Subject: Re: [PROPOSAL] Crypto extension
References: 1 2 3  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-11396@lists.php.net to get a copy of this message
> It's especially handy for Hash class. See following example (the > expressions for each example do exactly the same thing) > > <?php > use Crypto\Hash; > > // 1. just creating Hash object > $hash = new Hash('sha256'); > $hash = Hash::sha256(); > > // 2. creating object and updating context > $hash = new Hash('sha256', $message); > $hash = (new Hash('sha256'))->update($message); // PHP 5.4+ > $hash = Hash::sha256($message); > $hash = Hash::sha256()->update($message); > > // 3. crating object, updating context and returning hex digest string > $digest = (new Hash('sha256', $message))->hexdigest(); // PHP 5.4+ > $digest = (new Hash('sha256'))->update($message); // PHP 5.4+ > $digest = Hash::sha256($message)->hexdigest(); > $digest = Hash::sha256()->update($message)->hexdigest(); > > // * If you see some similarities with Python hashlib, then you are right! > I borrowed few ideas... :) > ?> > > I actually decided not to implement the first case from 2. and 3. example (new Hash($algorithm, $message)) as the second param is not needed (update can be used) and I plan to use that param for something else. I also forget to return hexdigest from one case. :) So the correct example is: <?php use Crypto\Hash; // 1. just creating Hash object $hash = new Hash('sha256'); $hash = Hash::sha256(); // 2. creating object and updating context $hash = (new Hash('sha256'))->update($message); // PHP 5.4+ $hash = Hash::sha256($message); $hash = Hash::sha256()->update($message); // 3. crating object, updating context and returning hex digest string $digest = (new Hash('sha256'))->update($message)->hexdigest(); // PHP 5.4+ $digest = Hash::sha256($message)->hexdigest(); $digest = Hash::sha256()->update($message)->hexdigest(); ?> Thanks Jakub

« previous php.pecl.dev (#11396) next »