| 574 | } |
| 575 | |
| 576 | Result HttpParseBasicCredentials(StringSpan authorizationHeader, Span<char> storage, StringSpan& username, |
| 577 | StringSpan& password) |
| 578 | { |
| 579 | username = {}; |
| 580 | password = {}; |
| 581 | |
| 582 | HttpAuthorizationView authorization; |
| 583 | SC_TRY(authorization.parse(authorizationHeader)); |
| 584 | SC_TRY_MSG(authorization.isBasic(), "Authorization scheme is not Basic"); |
| 585 | |
| 586 | size_t decodedSize = 0; |
| 587 | SC_TRY(HttpHeaderInternal::decodeBase64(authorization.credentials, storage, decodedSize)); |
| 588 | size_t colonIndex = static_cast<size_t>(-1); |
| 589 | for (size_t idx = 0; idx < decodedSize; ++idx) |
| 590 | { |
| 591 | if (storage.data()[idx] == ':') |
| 592 | { |
| 593 | colonIndex = idx; |
| 594 | break; |
| 595 | } |
| 596 | } |
| 597 | SC_TRY_MSG(colonIndex != static_cast<size_t>(-1), "Basic authorization missing password separator"); |
| 598 | |
| 599 | username = {{storage.data(), colonIndex}, false, StringEncoding::Ascii}; |
| 600 | password = {{storage.data() + colonIndex + 1, decodedSize - colonIndex - 1}, false, StringEncoding::Ascii}; |
| 601 | return Result(true); |
| 602 | } |
| 603 | |
| 604 | Result HttpWriteBearerAuthorization(StringSpan token, Span<char> storage, StringSpan& output) |
| 605 | { |