Source

security-level.ts

  1. import { Library, LoaderOptions } from './seal'
  2. export type SecurityLevelDependencies = {
  3. (): SecurityLevelConstructorOptions
  4. }
  5. export type SecurityLevelConstructorOptions = {
  6. (): SecurityLevel
  7. }
  8. export type SecurityLevel = {
  9. readonly none: any
  10. readonly tc128: any
  11. readonly tc192: any
  12. readonly tc256: any
  13. }
  14. const SecurityLevelConstructor =
  15. (library: Library): SecurityLevelDependencies =>
  16. (): SecurityLevelConstructorOptions =>
  17. (): SecurityLevel => {
  18. // Static methods
  19. const _none = library.SecLevelType.none
  20. const _tc128 = library.SecLevelType.tc128
  21. const _tc192 = library.SecLevelType.tc192
  22. const _tc256 = library.SecLevelType.tc256
  23. /**
  24. * @implements SecurityLevel
  25. */
  26. /**
  27. * @interface SecurityLevel
  28. */
  29. return {
  30. /**
  31. * Returns the 'none' security level
  32. *
  33. * @readonly
  34. * @name SecurityLevel.none
  35. * @type {SecurityLevel.none}
  36. */
  37. get none() {
  38. /**
  39. * @typedef {SecurityLevel.none} SecurityLevel.none
  40. */
  41. return _none
  42. },
  43. /**
  44. * Returns the '128' security level
  45. *
  46. * @readonly
  47. * @name SecurityLevel.tc128
  48. * @type {SecurityLevel.tc128}
  49. */
  50. get tc128() {
  51. /**
  52. * @typedef {SecurityLevel.tc128} SecurityLevel.tc128
  53. */
  54. return _tc128
  55. },
  56. /**
  57. * Returns the '192' security level
  58. *
  59. * @readonly
  60. * @name SecurityLevel.tc192
  61. * @type {SecurityLevel.tc192}
  62. */
  63. get tc192() {
  64. /**
  65. * @typedef {SecurityLevel.tc192} SecurityLevel.tc192
  66. */
  67. return _tc192
  68. },
  69. /**
  70. * Returns the '256' security level
  71. *
  72. * @readonly
  73. * @name SecurityLevel.tc256
  74. * @type {SecurityLevel.tc256}
  75. */
  76. get tc256() {
  77. /**
  78. * @typedef {SecurityLevel.tc256} SecurityLevel.tc256
  79. */
  80. return _tc256
  81. }
  82. }
  83. }
  84. export const SecurityLevelInit = ({
  85. loader
  86. }: LoaderOptions): SecurityLevelDependencies => {
  87. const library: Library = loader.library
  88. return SecurityLevelConstructor(library)
  89. }