Repository navigation
v8.0.0
Added
Fingerprint::make()andFingerprint::for(): SHA-256 fingerprints ofnull, booleans, integers, floats, strings and arrays, encoded with canonical format v1.- Associative keys are ordered canonically at every level, lists keep their order, and types are preserved (
1,'1',1.0andtrueall differ). - Closures, resources, unsupported objects,
NANand values nested deeper than 512 levels throw anUnsupportedValueExceptionthat names the offending path. - Filters:
ignore(),only()(path order never matters),ignoreWhen(),ignoreNulls(),ignoreEmptyStrings()andignoreEmptyArrays(). Lists stay lists and are re-indexed after removals; maps stay maps even when emptied. - Path rules:
at()scopes the following value rules to a dot path, andtransform()replaces a value before it is fingerprinted. Paths use php-dot-array's syntax:*matches one key or index, and\.,\*and\\escape a literal character. - List rules:
unordered(),sortBy()(one or more fields or dot paths, ascending or descending),sortUsing(),unique()anduniqueBy(). Lists are ordered first, then de-duplicated keeping the first occurrence; the rules leave maps and scalars alone. - String rules:
trim()andnormalizeWhitespace()(ASCII whitespace),lower()andupper()(UTF-8 through mbstring), andunicode()(NFC, NFD, NFKC, NFKD; needs ext-intl or symfony/polyfill-intl-normalizer). Invalid UTF-8 is rejected instead of silently replaced. - Number and boolean rules:
precision()rounds floats from their exact binary value, the same on every PHP version;normalizeNumericStrings()converts plain decimal strings;normalizeBooleans()mapstrue,1,'1','true'and their false counterparts. - Dates:
DateTimeInterfacevalues are fingerprinted by their UTC instant with microseconds;datePrecision()truncates them andkeepTimezone()keeps the local time and timezone instead. - Objects:
stdClass(always a map),JsonSerializable,Traversable(generators excluded) andnormalize(Class::class, $callback)for any class or interface. Other objects are rejected, private state is never read, and objects that contain themselves throw aCircularReferenceException. - Hashing:
algorithm()accepts any algorithmhash()supports (SHA-256 by default),hmac()signs with a secret, andhex(),binary(),base64()andbase64Url()choose the output. Unavailable algorithms and non-HMAC algorithms with a secret throw instead of falling back. namespace()keeps fingerprints of identical data used for different purposes apart.Fingerprint::verify()andFingerprintBuilder::verify()compare in constant time, hex case-insensitively.- The HMAC secret never appears in
var_dump(),print_r(), exception messages or exception traces, and builders refuse to be serialized. An algorithm that cannot do HMAC is therefore reported when hashing, not byhmac()itself. - Ordered signatures:
Fingerprint::signature($payload)->fields([...])joins the selected fields in exactly the declared order and hashes or signs them, for protocols such as payment gateway callbacks.valuesOnly()orkeyValue(),separator()andkeyValueSeparator()shape the message,onMissing()andonNull()decide what missing and null fields become (both throw by default), andat()applies string rules,precision()andtransform()per field.message()shows the exact string that is signed, andverify()checks a received signature in constant time. Fingerprint::file()andFingerprint::stream()fingerprint raw bytes in chunks, never loading a whole file into memory, with the same algorithm, HMAC, encoding andverify()options. Streams are read from their current position and are never rewound or closed. Missing files, directories and non-readable streams throw anUnreadableResourceException.FingerprintBuilder::result()returns aFingerprintResultwith the hash, algorithm, encoding, HMAC flag, namespace, format version, the exact canonical bytes and the normalized value as plain PHP data, to see why two fingerprints differ. It never holds the secret.maxDepth()changes the nesting limit (512 by default, likejson_decode()).FingerprintBuilder::for()reuses a configuration for another value. Invalid paths, path lists and callback results throw aConfigurationException.
Full Changelog: https://github.com/Pharaonic/php-fingerprint/commits/8.0.0