Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TT-2539] Refactor hash and token apis under internal/crypto, leave a…
…liases (#6838) ### **User description** <details open> <summary><a href="https://tyktech.atlassian.net/browse/TT-2539" title="TT-2539" target="_blank">TT-2539</a></summary> <br /> <table> <tr> <th>Summary</th> <td>Transaction/Access Logs</td> </tr> <tr> <th>Type</th> <td> <img alt="Story" src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10315?size=medium" /> Story </td> </tr> <tr> <th>Status</th> <td>In Code Review</td> </tr> <tr> <th>Points</th> <td>N/A</td> </tr> <tr> <th>Labels</th> <td><a href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20A%20ORDER%20BY%20created%20DESC" title="A">A</a>, <a href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20America's%20ORDER%20BY%20created%20DESC" title="America's">America's</a>, <a href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20CSE%20ORDER%20BY%20created%20DESC" title="CSE">CSE</a>, <a href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20Gold%20ORDER%20BY%20created%20DESC" title="Gold">Gold</a>, <a href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20QA_Fail%20ORDER%20BY%20created%20DESC" title="QA_Fail">QA_Fail</a>, <a href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20customer_request%20ORDER%20BY%20created%20DESC" title="customer_request">customer_request</a>, <a href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20innersource%20ORDER%20BY%20created%20DESC" title="innersource">innersource</a>, <a href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20jira_escalated%20ORDER%20BY%20created%20DESC" title="jira_escalated">jira_escalated</a></td> </tr> </table> </details> <!-- do not remove this marker as it will break jira-lint's functionality. added_by_jira_lint --> --- This is a prerequisite to implementing access logs, rebasing #6616 ___ ### **PR Type** Enhancement ___ ### **Description** - Refactored hash and token-related APIs into a new `internal/crypto` package. - Introduced modularized functions for hashing and token generation. - Removed redundant code from `storage` package and replaced with references to `crypto`. - Improved maintainability and modularity of cryptographic operations. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table> <tr> <td> <details> <summary><strong>hash.go</strong><dd><code>Introduced hash-related utilities in `internal/crypto`</code> </dd></summary> <hr> internal/crypto/hash.go <li>Added a new file for hash-related functions.<br> <li> Implemented <code>hashFunction</code> to support multiple algorithms.<br> <li> Created <code>HashStr</code> and <code>HashKey</code> for string hashing.<br> <li> Added constants for hash algorithm identifiers. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6838/files#diff-fd1c33ede81b9c5740cabc411ea8e4ce122cf642382b699114dfddcc49ea84d6">+60/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>token.go</strong><dd><code>Introduced token-related utilities in `internal/crypto`</code> </dd></summary> <hr> internal/crypto/token.go <li>Added a new file for token-related functions.<br> <li> Implemented <code>GenerateToken</code> for token creation with optional hashing.<br> <li> Added functions to extract token metadata (e.g., <code>TokenHashAlgo</code>, <br><code>TokenID</code>, <code>TokenOrg</code>).<br> <li> Improved handling of legacy and JSON-based tokens. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6838/files#diff-25b0099bc38076a27697918a7d82178f3f031a5abb58ae30c70c22d7332ee918">+91/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>storage.go</strong><dd><code>Refactored `storage` to use `internal/crypto`</code> </dd></summary> <hr> storage/storage.go <li>Removed hash and token-related functions from <code>storage</code>.<br> <li> Delegated cryptographic operations to <code>internal/crypto</code>.<br> <li> Cleaned up unused imports and constants. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6838/files#diff-2a93e444b612bd9853c32889fb82c4041760536f84356bb0db04738c19b62dde">+0/-125</a> </td> </tr> </table></td></tr><tr><td><strong>Miscellaneous</strong></td><td><table> <tr> <td> <details> <summary><strong>storage.go</strong><dd><code>Updated mock storage handler file</code> </dd></summary> <hr> storage/mock/storage.go <li>Regenerated mock file for storage handler.<br> <li> Removed unnecessary blank line. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6838/files#diff-0e75f439d0385d9272ea3afa9fc465dcae08554f19ff821e0743ad096325df40">+0/-1</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull request to receive relevant information Co-authored-by: Tit Petric <[email protected]>
- Loading branch information