import { computeHMACSHA256 , truncatedISO8061Date } from "../../common/utils/utils" ; import { SASProtocol } from "./IAccountSASSignatureValues" ; import { IIPRange , ipRangeToString } from "./IIPRange" ; export class export interface IQueueSASSignatureValues { type { string } memberof version ? : string ; type { SASProtocol | string } memberof protocol ? : SASProtocol | string ; type { Date | string } memberof startTime ? : Date | string ; type { Date | string } memberof expiryTime ? : Date | string ; /**
     * Optional only when identifier is provided.
     * Please refer to  QueueSASPermissions * being accessed for help constructing the permissions string.
     *
     *  type { string } memberof permissions ? : string ; type { IIPRange | string } memberof ipRange ? : IIPRange | string ; type { string } memberof queueName : string ; see https type { string } memberof identifier ? : string ; } export param { IQueueSASSignatureValues } queueSASSignatureValues param { SharedKeyCredential } sharedKeyCredential returns { SASQueryParameters } export function generateQueueSASSignature ( queueSASSignatureValues , accountName , sharedKey ) { if ( ! queueSASSignatureValues . identifier && ( ! queueSASSignatureValues . permissions && ! queueSASSignatureValues . expiryTime ) ) { throw new RangeError ( "Must provide 'permissions' and 'expiryTime' for Queue SAS generation when 'identifier' is not provided." ) ; } const version = queueSASSignatureValues . version ; const verifiedPermissions = queueSASSignatureValues . permissions ; const stringToSign = [ verifiedPermissions ? verifiedPermissions : "" , queueSASSignatureValues . startTime ? typeof queueSASSignatureValues . startTime === "string" ? queueSASSignatureValues . startTime : truncatedISO8061Date ( queueSASSignatureValues . startTime , false ) : "" , queueSASSignatureValues . expiryTime ? typeof queueSASSignatureValues . expiryTime === "string" ? queueSASSignatureValues . expiryTime : truncatedISO8061Date ( queueSASSignatureValues . expiryTime , false ) : "" , getCanonicalName ( accountName , queueSASSignatureValues . queueName ) , queueSASSignatureValues . identifier , queueSASSignatureValues . ipRange ? typeof queueSASSignatureValues . ipRange === "string" ? queueSASSignatureValues . ipRange : ipRangeToString ( queueSASSignatureValues . ipRange ) : "" , queueSASSignatureValues . protocol ? queueSASSignatureValues . protocol : "" , version ] . join ( "\n" ) ; const signature = computeHMACSHA256 ( stringToSign , sharedKey ) ; return [ signature , stringToSign ] ; } function getCanonicalName ( accountName , queueName ) { return `/queue/${ accountName }/${ queueName }` ; }