nyamsprod, French
@nyamsprod@phpc.social avatar

I wish #PHP had two things and none of them involve generics... I wish it had type aliases and a native base32 encoding/decoding mechanism (in a class or a pair of functions I do not care)

derickr,
@derickr@phpc.social avatar

@nyamsprod I bet you could make a patch!

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr I wish I could really

derickr,
@derickr@phpc.social avatar

@nyamsprod You can give it a try? Happy to be a guide

Girgias,
@Girgias@phpc.social avatar

@nyamsprod @derickr the base 32 ones shouldn't be too difficult to do, type aliases are a different level of conplexi tho :-/

nyamsprod,
@nyamsprod@phpc.social avatar

@Girgias @derickr here's a simple proposition not entirely flesh out. Still rough but a general idea to think about let me know your thought https://gist.github.com/nyamsprod/8a5cf21c136952a46ec8836f29738c82

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias I'll get to a full response after the break, but I think I'd be in favour of just the simple functions.

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias no problem take your time I wanted to put my thoughts into words before the break and yes the proposal can evolve

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias Alright, I just had a longer look, and (of course) found that base32 is more complicated than expected:

  1. There are two standards in RFC4648.
  2. A bunch of other mappings are also common: https://en.wikipedia.org/wiki/Base32#Alternative_encoding_schemes
  3. accepting strings with 0, 1, 8, l, L, might require allowing for user-defined mappings.

Ideally the API looks the same as for base64, but I think it would be too simple to allow for all requirements. I wouldn't want to see a class for this though.

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias did you have a chance to check how Python did it ? They use to have functions with signature similar to our current base64 approach but they did revamp the API https://docs.python.org/3/library/base64.html
Again I am not sure as you said that all should be covered but I believe being able to encode/decode hex and ascii should be possible natively

derickr,
@derickr@phpc.social avatar

@nyamsprod @Girgias I did check python, but found it rather clunky 🙂

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias If we stick with functions a la base64 we then need to add extra variables - the alphabet and maybe the padding character. so that user land can switch the alphabet and/or the padding character as they want PHP would only provide the Hex and Us-Ascii alphabet (those from the RFC)
So for encoding you would have at most 3 parameters and 4 on decode.

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr @Girgias following our last discussion I createed a polyfill using functions only let me know if this is what you had in mind. https://github.com/bakame-php/aide/tree/main/src/Base32
The implementation does not really matter what matter most is the API

nyamsprod,
@nyamsprod@phpc.social avatar

@derickr the best I could do is maybe creating the RFC and probably help with building the test suite but my knowledge of C is really not that great. Might be a goal for 2024 (talking about base32) type alias requires I believe a deeper knowledge of PHP internals that I really do not have

derickr,
@derickr@phpc.social avatar

@nyamsprod Type alias i agree with, but base32 should be possible :-) Happy to help

timwolla,
@timwolla@phpc.social avatar

@nyamsprod Agreed with regard to base32. Though my use cases so far have all been security-sensitive (TOTP secrets), thus needing to use https://github.com/paragonie/constant_time_encoding anyway.

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