crypt.d.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @license
  3. * Copyright 2017 Google LLC
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. interface Base64 {
  18. byteToCharMap_: {
  19. [key: number]: string;
  20. } | null;
  21. charToByteMap_: {
  22. [key: string]: number;
  23. } | null;
  24. byteToCharMapWebSafe_: {
  25. [key: number]: string;
  26. } | null;
  27. charToByteMapWebSafe_: {
  28. [key: string]: number;
  29. } | null;
  30. ENCODED_VALS_BASE: string;
  31. readonly ENCODED_VALS: string;
  32. readonly ENCODED_VALS_WEBSAFE: string;
  33. HAS_NATIVE_SUPPORT: boolean;
  34. encodeByteArray(input: number[] | Uint8Array, webSafe?: boolean): string;
  35. encodeString(input: string, webSafe?: boolean): string;
  36. decodeString(input: string, webSafe: boolean): string;
  37. decodeStringToByteArray(input: string, webSafe: boolean): number[];
  38. init_(): void;
  39. }
  40. export declare const base64: Base64;
  41. /**
  42. * An error encountered while decoding base64 string.
  43. */
  44. export declare class DecodeBase64StringError extends Error {
  45. readonly name = "DecodeBase64StringError";
  46. }
  47. /**
  48. * URL-safe base64 encoding
  49. */
  50. export declare const base64Encode: (str: string) => string;
  51. /**
  52. * URL-safe base64 encoding (without "." padding in the end).
  53. * e.g. Used in JSON Web Token (JWT) parts.
  54. */
  55. export declare const base64urlEncodeWithoutPadding: (str: string) => string;
  56. /**
  57. * URL-safe base64 decoding
  58. *
  59. * NOTE: DO NOT use the global atob() function - it does NOT support the
  60. * base64Url variant encoding.
  61. *
  62. * @param str To be decoded
  63. * @return Decoded result, if possible
  64. */
  65. export declare const base64Decode: (str: string) => string | null;
  66. export {};