Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97655 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60322 invoked from network); 10 Jan 2017 08:23:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jan 2017 08:23:46 -0000 Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.218.42 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.218.42 mail-oi0-f42.google.com Received: from [209.85.218.42] ([209.85.218.42:34505] helo=mail-oi0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9C/C0-55699-11A94785 for ; Tue, 10 Jan 2017 03:23:46 -0500 Received: by mail-oi0-f42.google.com with SMTP id 3so537844623oih.1 for ; Tue, 10 Jan 2017 00:23:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golemon-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to; bh=on816gJiJQUQVGU52LRz/JrDEybLeqcFVzldtYKEDJg=; b=px62o2lD416qSpLUgtZu0hkZ0BT1aNDO3lVJrukRaufdnfEMf6PSWzv5Ril2DWsKTL f4rV9h7rVTR8f2V2jIdVVLudgyuH0BpNBaiiYODqZtoWijiURCuWEgNgWIhO0MpN+bVQ QnnroUGqKxWbvS5ChUCftYyrnYtwwPHFrRSOxv5ITkvFtZ4YB+0I6EnYGewcjDuqC/Uf +ScscgjALk7eMLrx5ilqX5AIopsgXz2YOd3KIBWU23e7eGcFKYL/wfDnNq8tWYO9fx9q XtYgcmXwa+hPUY9MU4WfqmjLstMIUY5QNvcP5Oa0Da+ozTytBDjVo9amq2KEi5A7MSHu zMrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to; bh=on816gJiJQUQVGU52LRz/JrDEybLeqcFVzldtYKEDJg=; b=W9aSLOOWcGQG8b2g4k1uYPh3mZqjPUWRc/AkVOARH/66EWXHAYI2G2/TBAYgxBRvdB 8w7iYR0MAgkSTgdQDPuQeCY25hWgVANbqKcWLmKB2f2dRrQkEcWxY986XsZqCntuxVA8 0lMwDFuKiG89bx7EdeWt8/IoKjmpM3NUEZp+8vRhJlWAV9adDxkH0I0ZwgaQztt7Cr02 Kh7e6bk2BtVGL159tc+RQJ8GnX94wQSgeDBKYmZV+GQNY2OcVrOAA0+Tv7016pgIk77u p/wYmQtm4mFb/HUBR0Zd6ZTUx+sRDzyUYqVRFpvqX3FvwByGFHOOk7df6jUII0XJsb7r xyRQ== X-Gm-Message-State: AIkVDXJVGSXAf282MiHORl+0CdnyTm2S9U0s8mQ4MgpnK14xl4fItfkdhwZPGHCXlL/G6qUd7Irvbi6AjMrLdQ== X-Received: by 10.157.13.166 with SMTP id 35mr973860ots.140.1484036622994; Tue, 10 Jan 2017 00:23:42 -0800 (PST) MIME-Version: 1.0 Sender: php@golemon.com Received: by 10.157.39.197 with HTTP; Tue, 10 Jan 2017 00:23:42 -0800 (PST) X-Originating-IP: [2605:e000:ccc7:eb00:9deb:62b5:176e:322b] In-Reply-To: References: Date: Tue, 10 Jan 2017 00:23:42 -0800 X-Google-Sender-Auth: 6VtIkESd26QndVYig2R7fRxRemc Message-ID: To: PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Fwd: [RFC] HashContext as Object From: pollita@php.net (Sara Golemon) On Thu, Dec 29, 2016 at 6:32 PM, Sara Golemon wrote: > On Mon, Dec 26, 2016 at 7:35 PM, Sara Golemon wrote: >> I was trawling through Pull Requests and found #660 which I think is a >> nice idea and deserves some attention. It involves minor BC however, >> so I've updated the patch and presented it for your discussing >> pleasure. >> > Specifically, I should say I'm eager to hear thoughts on the item > listed as an Open Issue. > > That is: Currently hash_final() destroys the existing HashContext > resource immediately. No hope of continuing or even just reissuing > the result. > > I'm quite tempted atm, to go the "copy the context, finalize to get a > digest, then restoring to the saved context state". For most use > cases of this API this is a slight overhead add since the context is > being duplicated then shortly thereafter discarded. (Bear in mind > though, that the hash_init->hash_update->hash_final API is the edge > case already compared to the all-in-one hash() and hash_hmac() > functions). > > What doing this does offer, however, is a pathway to reasonable APIs > for streaming hash functions (see SHA3/Keccak Sponge Functions). As a > minor side benefit, we also get an idempotent hash_final(). So even > though there's a VERY minor BC break involved, I think it's the right > thing to do. If others agree, I'll update the diff to reflect. > Still looking for comments/feedback on Open Issue (above). I've implemented what it would look like as a stacked commit on the feature branch: https://github.com/php/php-src/compare/master...sgolemon:pr-660 though I could easily squash before commit if it's voted in. The downside of this is pretty obvious, a completely unnecessary duplication in the majority of the use cases. But the upside is that HashContext actually behaves how you'd expect a normal object to behave. The idea of freezing an object on calling hash_final() (or $hash->final(), eventually) makes me twitch a bit. If I get no feedback at all, I'll just make it a secondary vote: Do it? "Yes", "No". And if Yes, then: "Keeping `freeze` behavior", or "Include context-preservation." FWIW, I think I'm actually favoring the idea of keeping the freeze behavior of just the original implementation, and not including this latest update. -Sara