"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HashEncodingPathStorage = void 0;
const crypto_1 = require("crypto");
const LogUtil_1 = require("../../logging/LogUtil");
const NotImplementedHttpError_1 = require("../../util/errors/NotImplementedHttpError");
const PathUtil_1 = require("../../util/PathUtil");
const EncodingPathStorage_1 = require("./EncodingPathStorage");
/**
 * A variant of the {@link EncodingPathStorage} that hashes the key instead of converting to base64 encoding.
 *
 * This class was created specifically to prevent the issue of identifiers being too long when storing data:
 * https://github.com/CommunitySolidServer/CommunitySolidServer/issues/1013
 *
 * This should eventually be replaced by a more structural approach once internal storage has been refactored
 * and data migration from older versions and formats is supported.
 */
class HashEncodingPathStorage extends EncodingPathStorage_1.EncodingPathStorage {
    constructor() {
        super(...arguments);
        this.logger = (0, LogUtil_1.getLoggerFor)(this);
    }
    keyToPath(key) {
        const hash = (0, crypto_1.createHash)('sha256').update(key).digest('hex');
        this.logger.debug(`Hashing key ${key} to ${hash}`);
        return (0, PathUtil_1.joinUrl)(this.basePath, hash);
    }
    pathToKey() {
        throw new NotImplementedHttpError_1.NotImplementedHttpError('Hash keys cannot be converted back.');
    }
}
exports.HashEncodingPathStorage = HashEncodingPathStorage;
//# sourceMappingURL=HashEncodingPathStorage.js.map