'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
 * A static-key-based credential that supports updating
 * the underlying key value.
 */
var AzureKeyCredential = /** @class */ (function () {
    /**
     * Create an instance of an AzureKeyCredential for use
     * with a service client.
     *
     * @param key - The initial value of the key to use in authentication
     */
    function AzureKeyCredential(key) {
        if (!key) {
            throw new Error("key must be a non-empty string");
        }
        this._key = key;
    }
    Object.defineProperty(AzureKeyCredential.prototype, "key", {
        /**
         * The value of the key to be used in authentication
         */
        get: function () {
            return this._key;
        },
        enumerable: false,
        configurable: true
    });
    /**
     * Change the value of the key.
     *
     * Updates will take effect upon the next request after
     * updating the key value.
     *
     * @param newKey - The new key value to be used
     */
    AzureKeyCredential.prototype.update = function (newKey) {
        this._key = newKey;
    };
    return AzureKeyCredential;
}());

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
 * A static-signature-based credential that supports updating
 * the underlying signature value.
 */
var AzureSASCredential = /** @class */ (function () {
    /**
     * Create an instance of an AzureSASCredential for use
     * with a service client.
     *
     * @param signature - The initial value of the shared access signature to use in authentication
     */
    function AzureSASCredential(signature) {
        if (!signature) {
            throw new Error("shared access signature must be a non-empty string");
        }
        this._signature = signature;
    }
    Object.defineProperty(AzureSASCredential.prototype, "signature", {
        /**
         * The value of the shared access signature to be used in authentication
         */
        get: function () {
            return this._signature;
        },
        enumerable: false,
        configurable: true
    });
    /**
     * Change the value of the signature.
     *
     * Updates will take effect upon the next request after
     * updating the signature value.
     *
     * @param newSignature - The new shared access signature value to be used
     */
    AzureSASCredential.prototype.update = function (newSignature) {
        if (!newSignature) {
            throw new Error("shared access signature must be a non-empty string");
        }
        this._signature = newSignature;
    };
    return AzureSASCredential;
}());

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
 * Tests an object to determine whether it implements TokenCredential.
 *
 * @param credential - The assumed TokenCredential to be tested.
 */
function isTokenCredential(credential) {
    // Check for an object with a 'getToken' function and possibly with
    // a 'signRequest' function.  We do this check to make sure that
    // a ServiceClientCredentials implementor (like TokenClientCredentials
    // in ms-rest-nodeauth) doesn't get mistaken for a TokenCredential if
    // it doesn't actually implement TokenCredential also.
    var castCredential = credential;
    return (castCredential &&
        typeof castCredential.getToken === "function" &&
        (castCredential.signRequest === undefined || castCredential.getToken.length > 0));
}

exports.AzureKeyCredential = AzureKeyCredential;
exports.AzureSASCredential = AzureSASCredential;
exports.isTokenCredential = isTokenCredential;
//# sourceMappingURL=index.js.map
