Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument 2 passed to Safe\openssl_sign() must be of the type string, null given #86

Closed
JanMikes opened this issue Jan 26, 2019 · 4 comments

Comments

@JanMikes
Copy link

JanMikes commented Jan 26, 2019

Hello!

I have following code:

// $this->privateKey is resource
$digestText = '';
\Safe\openssl_sign($digestText, $signature, $this->privateKey);

And i get following error: Argument 2 passed to Safe\openssl_sign() must be of the type string, null given

I can get this fixed by adding $signature = '' before calling openssl_sign(). I understand the error, but i expected (and it worked before using Safe package), that $signature variable will get created 😄

@moufmouf
Copy link
Member

Hey @JanMikes ,

Ok, I can confirm I reproduced the issue in this unit test: #91 .
Still have to find a workaround!

@moufmouf
Copy link
Member

Ok, found a way.

The PHPStan function map tells us if a parameter passed by reference (like $signature) is supposed to be used for read and write or for write only.

Typically, $signature is a write only parameter. Any write only parameter should be considered as nullable (even if they are not documented as such), since we can put null in input and they will produce a string output.

PHPStan's functionMap.php

'openssl_sign' => ['bool', 'data'=>'string', '&w_signature'=>'string', 'priv_key_id'=>'resource|string', 'signature_alg='=>'int|string'],

The "w_" in the file denotes the "write only" mode.

@JanMikes
Copy link
Author

JanMikes commented Feb 2, 2019

Thank you very much, I will try it out.

@moufmouf
Copy link
Member

moufmouf commented Feb 2, 2019

Fixed in #91

@moufmouf moufmouf closed this as completed Feb 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants