mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-22 00:22:57 -05:00
50 lines
2.2 KiB
C++
50 lines
2.2 KiB
C++
#include "SceTypes.hpp"
|
|
#include <array>
|
|
#include <cstdlib>
|
|
#include <stdexcept>
|
|
|
|
extern "C" {
|
|
int APS5_VABI sceNpAuthCreateRequest();
|
|
int APS5_VABI sceNpAuthDeleteRequest(int);
|
|
int APS5_VABI sceNpAuthGetAuthorizedAppCode(std::int32_t, const NpAuthAuthorizedAppCodeParameter*, char*, std::int32_t*, bool*);
|
|
}
|
|
|
|
static void Require(bool condition) {
|
|
if (!condition) std::abort();
|
|
}
|
|
|
|
int main() {
|
|
constexpr auto invalidArgument = static_cast<int>(0x80550301u);
|
|
constexpr auto invalidSize = static_cast<int>(0x80550302u);
|
|
constexpr auto requestNotFound = static_cast<int>(0x80550306u);
|
|
std::array<char, 136> client{};
|
|
std::array<char, 128> code{};
|
|
code.fill('x');
|
|
const auto original = code;
|
|
bool authorizationRequired = true;
|
|
NpAuthAuthorizedAppCodeParameter parameter{40, 1, reinterpret_cast<const NpAuthClientId*>(client.data()), "", 0};
|
|
Require(sceNpAuthGetAuthorizedAppCode(0, nullptr, code.data(), nullptr, &authorizationRequired) == invalidArgument);
|
|
parameter.size = 39;
|
|
Require(sceNpAuthGetAuthorizedAppCode(0, ¶meter, code.data(), nullptr, &authorizationRequired) == invalidSize);
|
|
parameter.size = 40;
|
|
Require(sceNpAuthGetAuthorizedAppCode(0, ¶meter, nullptr, nullptr, &authorizationRequired) == invalidArgument);
|
|
Require(sceNpAuthGetAuthorizedAppCode(0, ¶meter, code.data(), nullptr, nullptr) == invalidArgument);
|
|
parameter.option = 2;
|
|
Require(sceNpAuthGetAuthorizedAppCode(0, ¶meter, code.data(), nullptr, &authorizationRequired) == invalidArgument);
|
|
parameter.option = 0;
|
|
parameter.userId = -1;
|
|
Require(sceNpAuthGetAuthorizedAppCode(0, ¶meter, code.data(), nullptr, &authorizationRequired) == invalidArgument);
|
|
parameter.userId = 1;
|
|
Require(sceNpAuthGetAuthorizedAppCode(0, ¶meter, code.data(), nullptr, &authorizationRequired) == requestNotFound);
|
|
const auto requestId = sceNpAuthCreateRequest();
|
|
Require(requestId > 0);
|
|
bool threw = false;
|
|
try {
|
|
sceNpAuthGetAuthorizedAppCode(requestId, ¶meter, code.data(), nullptr, &authorizationRequired);
|
|
} catch (const std::logic_error&) {
|
|
threw = true;
|
|
}
|
|
Require(threw && code == original && authorizationRequired);
|
|
Require(sceNpAuthDeleteRequest(requestId) == 0);
|
|
}
|