"use strict";
/**
 * @adonisjs/http-server
 *
 * (c) Harminder Virk <virk@adonisjs.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.unpack = exports.canUnpack = exports.pack = void 0;
const helpers_1 = require("@poppinss/utils/build/helpers");
/**
 * Encodes a value into a base64 url encoded string to
 * be set as cookie
 */
function pack(value) {
    if (value === undefined || value === null) {
        return null;
    }
    return helpers_1.base64.urlEncode(new helpers_1.MessageBuilder().build(value));
}
exports.pack = pack;
/**
 * Returns true when this `unpack` method of this module can attempt
 * to unpack the encode value.
 */
function canUnpack(encodedValue) {
    return typeof encodedValue === 'string';
}
exports.canUnpack = canUnpack;
/**
 * Attempts to unpack the value by decoding it. Make sure to call, `canUnpack`
 * before calling this method
 */
function unpack(encodedValue) {
    const verified = new helpers_1.MessageBuilder().verify(helpers_1.base64.urlDecode(encodedValue, 'utf-8', true));
    return verified === undefined ? null : verified;
}
exports.unpack = unpack;
