Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72923 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93100 invoked from network); 5 Mar 2014 14:46:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Mar 2014 14:46:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.53 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.219.53 mail-oa0-f53.google.com Received: from [209.85.219.53] ([209.85.219.53:56318] helo=mail-oa0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/01-21412-3D837135 for ; Wed, 05 Mar 2014 09:46:43 -0500 Received: by mail-oa0-f53.google.com with SMTP id j17so1066947oag.26 for ; Wed, 05 Mar 2014 06:46:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=winRiQkHTo5YJuSzu4Uz5tllKLIsEHRDpKnpC7Il6aI=; b=YCIouKuPrHLPbXglRzosKrxEV1azI4tLBMz8KgZObNukyEhVyPUXMkRDWH9ImvEcxw T76gEBRKbYJrVF7yGV101+4Rkl0LC2JWC0fH5MV55HRzHLv39/IEeAq/5u6XUaSFC2Ih jY7XTuqQebaly/CO/VRgk4Er4xT6LSk+atS7XcE2n8982/+v35eEvENyNEHsHXgfGCMU x/3fN3nY4U7URkHBMTjt2DSCytVoD2xTJj0Vk/G9J559645aC9XuLjJ3iY9c094rLpbV ttf5UJ+JeUKSGU3OLwfv9Gv+7DHwDSVL2eFZ2joHT9Z/2n50MxBYIAuxeyWJO5H520oi iF9Q== MIME-Version: 1.0 X-Received: by 10.60.62.146 with SMTP id y18mr815995oer.24.1394030800214; Wed, 05 Mar 2014 06:46:40 -0800 (PST) Received: by 10.182.69.101 with HTTP; Wed, 5 Mar 2014 06:46:40 -0800 (PST) In-Reply-To: References: Date: Wed, 5 Mar 2014 15:46:40 +0100 Message-ID: To: Derick Rethans Cc: Andrey Andreev , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b6769e8a76e0504f3dd1687 Subject: Re: [PHP-DEV] Stricter error handling in mcrypt extension From: nikita.ppv@gmail.com (Nikita Popov) --047d7b6769e8a76e0504f3dd1687 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Mar 5, 2014 at 1:56 PM, Derick Rethans wrote: > On Wed, 5 Mar 2014, Nikita Popov wrote: > > > On Tue, Mar 4, 2014 at 9:32 PM, Andrey Andreev wrote: > > > > > Speaking of bugs in MCrypt and IVs ... in ECB mode it complains if > > > you don't pass an IV, even though it is ignored afterwards. > > > > You're probably referring to mcrypt_generic here, rather than > > mcrypt_encrypt. I can bring that function in line with mcrypt_encrypt, > > i.e. add the same error checks and make the IV only required if the > > mode requires it. > > > > However I'm not sure what kind of return value I should use with this > > function. Currently it returns a long result, which is 0 on success > > and a negative number on error. However mcrypt does not define error > > codes for all possible error conditions, e.g. while it has a code for > > invalid key sizes, it doesn't have a code for invalid IV sizes. > > > > Personally I'd just switch it to true/false for success/error, as the > > warnings already tell you what kind of error occurred. Would that be > > okay with you, Derick? > > No - as that is a BC break of a deliberate (though crappy ;-)) API. The > result values of mcrypt_generic_init() (which is I think what you're > refering too) are documented too: > > The function returns a negative value on error: -3 when the key > length was incorrect, -4 when there was a memory allocation problem > and any other return value is an unknown error. If an error occurs > a > warning will be displayed accordingly. FALSE is returned if > incorrect parameters were passed. > > cheers, > Derick > Yeah, it would be kinda ugly to have "falsy" be success in one version and be failure in the next... I applied the changes to mcrypt_encrypt/mcrypt_decrypt/mcrypt_{MODE} now and left mcrypt_generic_init() alone. Most people should be using the encrypt/decrypt functions anyway. Nikita --047d7b6769e8a76e0504f3dd1687--