nyamsprod, French
@nyamsprod@phpc.social avatar

@derickr @Girgias I have updated my Draft RFC for base32_encode/base32_decode. Let me know what you think about the new proposal.
https://gist.github.com/nyamsprod/8a5cf21c136952a46ec8836f29738c82

Girgias,
@Girgias@phpc.social avatar

@nyamsprod @derickr Makes sense to me :)

nyamsprod,
@nyamsprod@phpc.social avatar

@Girgias @derickr added support for the padding character. base32_encode may now also return false if the submitted alphabet or padding is invalid.

Girgias,
@Girgias@phpc.social avatar

@nyamsprod @derickr I'd throw an exception when providing an invalid alphabet personally :)

nyamsprod,
@nyamsprod@phpc.social avatar

@Girgias @derickr I have a polyfill in which I do throw an exception but PHP function do not throw exception normally unless in this case it becomes possible to do so. https://github.com/bakame-php/aide-base32

Girgias,
@Girgias@phpc.social avatar

@nyamsprod @derickr It's a new function, and plenty of functions now throw ValueErrors, which was providing an invalid alphabet is to me

nyamsprod,
@nyamsprod@phpc.social avatar

@Girgias @derickr so ValueError for alphabet and padding and false for everything else concerning decoding then .. noted I will change the wording then. And it makes encoding always returning a string which is better.

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias I don't really have anything to add, so ... time for the code and RFC? ;-)

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias what's easier to start with the code or the RFC process ? I presume both can be made in parallel. That's brand new territories from me so any advice is welcomed. Also since I do not know C I can create a branch and already add tests if that can help

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias An RFC is probably easier to write... but I have always found it easier for changes like this to also do the implementation, as that sometimes informs me what the RFC needs to contain.

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias OK when I have time will fork and create a branch with the expected tests to start wiith

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias I will create a branch and add the tests files for the implementation I think that all I can do since I do not know C. On that note any reason base64_encode/decode tests are under the url folder and not the strings folder in the php-src codebase 🤔. I wanted to put the tests for base32 beside those of base64 so it seems strange to me

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias I have no idea why they are there either. But yeah, it's probably best to put the base32 tests alongside the base64 ones.

Perhaps you can write the encoding algorithm in PHP? It usually not that hard to translate to C!

Were you also going to make an RFC?

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias I already wrote the implementation in PHP https://github.com/bakame-php/aide-base32/blob/main/Base32.php hence why I already have tests that I can backport from PHPUnit -> phpt

For the RFC I will copy/paste the draft I already wrote once the implementation is done in case we discover something we haven't thought about

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias Ah, now you only need to port it to C ;-)

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias I see base64_encode is getting an option argument to remove the padding ... should I already take this into consideration for base32_encode also or not ?

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias If it happens, probably. Haven't looked at that change to base64 yet

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias I updated my php codebase and remove all non string function except for array_key_exists and unpack I hope to create a PR to the php-src master with the tests ported hopefully first week of april. then I will ask for karma to create/ copy/paste my RFC for base32_(encode|decode) I might add the base32.h file but still checking how to write that one

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias
https://github.com/bakame-php/php-src/pull/1/files

Let me know if I am on the right track or not. I will then update the code accordingly I believe the base32.c will remain empty 😆

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias Left a few comments. I am getting you to write the C implementation too :-þ

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias I see that.... Hope I'm not butchering the language

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias fixed your comment base32.c is populated with something 👌
Now only thing left is the C implementation I guess

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias anything I can do for the base32encode PR ? Only thing left is porting my PHP code to C and align it to php-src expectation I guess 😅

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias Try your hand at the c implementation? I'm not going to have time for a while

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias I'm going to try not sure about the result

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias I think I more or less was able to do base32_encode I'm still missing how I could rewrite this in C

$chars = (array) unpack('C*', $decoded);

Is there a way to call PHP implemetation of unpack directly 🤔 I presume there is but I have not found it or recognized it

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias Can you explain what this does in PHP? I'm not too familiar with unpack

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias
https://3v4l.org/iujGt

it converts the string characters into their byte representations and returns the result as an array

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias strings ( char[]) in C are already arrays of bytes, so there is little to nothing to do.

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias nice ... should then ease my conversion. will try to finish that one so you can see/review my horrible code. Once stable I will tackle the base32_decode which is more complex IMHO

nyamsprod, (edited )
@nyamsprod@phpc.social avatar

@derickr @Girgias https://github.com/bakame-php/php-src/pull/1/commits/61ab6aa33c6276b7eb8baea87578e8bd843b3c8e Added base32_encode .. you can take your red pen 😅 I'm pretty sure there are stuff that needs correction

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias I had a very quick look, and it looks like a good start. I'll have a better look later, but two suggestions right away:

  1. When you create any zend_string and don't use it beyond the function, you need to free up the allocated memory, (zend_string_release), otherwise you're leaking it.

If you run the tests with: php run-tests.php -m ext/standard it will run with valgrind enabled to check for this (you might have to install it).

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias
2. Functions like strcspn() that operate on C strings are not null safe. I am sure there will be a null safe implementation somewhere in PHP's API, but can't remember the name on the top of my head.

  1. You use smart_strings for which are close to PHP strings, but it's likely going to be much faster to preallocate the result buffer once with the right size.

I'm traveling the next few days, so might take a while to properly review. But a great start.

derickr,
@derickr@phpc.social avatar
nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias yes I saw it been a bit busy with work related tasks. Will continue on the implementation next week if all settles down a bit

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias That's Ok! Was just making sure that you had seen it.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines