static create()

in src/common-core/shared_access_signature.ts [91:117]


  static create(resourceUri: string, keyName: string, key: string, expiry: number | string): SharedAccessSignature {
    function throwRef(name: string, value: any): void {
      throw new ReferenceError('Argument \'' + name + '\' is ' + value);
    }

    /*Codes_SRS_NODE_COMMON_SAS_05_009: [If resourceUri, key, or expiry are falsy (i.e., undefined, null, or empty), create shall throw ReferenceException.]*/
    if (!resourceUri) throwRef('resourceUri', resourceUri);
    if (!key) throwRef('key', key);
    if (!expiry) throwRef('expiry', expiry);

    /*Codes_SRS_NODE_COMMON_SAS_05_010: [The create method shall create a new instance of SharedAccessSignature with properties: sr, sig, se, and optionally skn.]*/
    const sas = new SharedAccessSignature();
    sas._key = key;
    /*Codes_SRS_NODE_COMMON_SAS_05_011: [The sr property shall have the value of resourceUri.]*/
    sas.sr = resourceUri;
    /*Codes_SRS_NODE_COMMON_SAS_05_018: [If the keyName argument to the create method was falsy, skn shall not be defined.]*/
    /*Codes_SRS_NODE_COMMON_SAS_05_017: [<urlEncodedKeyName> shall be the URL-encoded value of keyName.]*/
    /*Codes_SRS_NODE_COMMON_SAS_05_016: [The skn property shall be the value <urlEncodedKeyName>.]*/
    if (keyName) sas.skn = authorization.encodeUriComponentStrict(keyName);
    /*Codes_SRS_NODE_COMMON_SAS_05_015: [The se property shall have the value of expiry.]*/
    sas.se = expiry;
    /*Codes_SRS_NODE_COMMON_SAS_05_013: [<signature> shall be an HMAC-SHA256 hash of the value <stringToSign>, which is then base64-encoded.]*/
    /*Codes_SRS_NODE_COMMON_SAS_05_014: [<stringToSign> shall be a concatenation of resourceUri + '\n' + expiry.]*/
    /*Codes_SRS_NODE_COMMON_SAS_05_012: [The sig property shall be the result of URL-encoding the value <signature>.]*/
    sas.sig = authorization.encodeUriComponentStrict(authorization.hmacHash(sas._key, authorization.stringToSign(sas.sr, sas.se.toString())));
    return sas;
  }