noop.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. // Copyright (c) 2025 Tulir Asokan
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. package store
  7. import (
  8. "context"
  9. "errors"
  10. "time"
  11. "git.bobomao.top/joey/testwh/types"
  12. "git.bobomao.top/joey/testwh/util/keys"
  13. )
  14. type NoopStore struct {
  15. Error error
  16. }
  17. var nilStore = &NoopStore{Error: errors.New("store is nil")}
  18. var nilKey = &keys.KeyPair{Priv: &[32]byte{}, Pub: &[32]byte{}}
  19. var NoopDevice = &Device{
  20. ID: &types.EmptyJID,
  21. NoiseKey: nilKey,
  22. IdentityKey: nilKey,
  23. Identities: nilStore,
  24. Sessions: nilStore,
  25. PreKeys: nilStore,
  26. SenderKeys: nilStore,
  27. AppStateKeys: nilStore,
  28. AppState: nilStore,
  29. Contacts: nilStore,
  30. ChatSettings: nilStore,
  31. MsgSecrets: nilStore,
  32. PrivacyTokens: nilStore,
  33. EventBuffer: nilStore,
  34. LIDs: nilStore,
  35. Container: nilStore,
  36. }
  37. var _ AllStores = (*NoopStore)(nil)
  38. var _ DeviceContainer = (*NoopStore)(nil)
  39. func (n *NoopStore) PutIdentity(ctx context.Context, address string, key [32]byte) error {
  40. return n.Error
  41. }
  42. func (n *NoopStore) DeleteAllIdentities(ctx context.Context, phone string) error {
  43. return n.Error
  44. }
  45. func (n *NoopStore) DeleteIdentity(ctx context.Context, address string) error {
  46. return n.Error
  47. }
  48. func (n *NoopStore) IsTrustedIdentity(ctx context.Context, address string, key [32]byte) (bool, error) {
  49. return false, n.Error
  50. }
  51. func (n *NoopStore) GetSession(ctx context.Context, address string) ([]byte, error) {
  52. return nil, n.Error
  53. }
  54. func (n *NoopStore) HasSession(ctx context.Context, address string) (bool, error) {
  55. return false, n.Error
  56. }
  57. func (n *NoopStore) GetManySessions(ctx context.Context, addresses []string) (map[string][]byte, error) {
  58. return nil, n.Error
  59. }
  60. func (n *NoopStore) PutSession(ctx context.Context, address string, session []byte) error {
  61. return n.Error
  62. }
  63. func (n *NoopStore) PutManySessions(ctx context.Context, sessions map[string][]byte) error {
  64. return n.Error
  65. }
  66. func (n *NoopStore) DeleteAllSessions(ctx context.Context, phone string) error {
  67. return n.Error
  68. }
  69. func (n *NoopStore) DeleteSession(ctx context.Context, address string) error {
  70. return n.Error
  71. }
  72. func (n *NoopStore) MigratePNToLID(ctx context.Context, pn, lid types.JID) error {
  73. return n.Error
  74. }
  75. func (n *NoopStore) GetOrGenPreKeys(ctx context.Context, count uint32) ([]*keys.PreKey, error) {
  76. return nil, n.Error
  77. }
  78. func (n *NoopStore) GenOnePreKey(ctx context.Context) (*keys.PreKey, error) {
  79. return nil, n.Error
  80. }
  81. func (n *NoopStore) GetPreKey(ctx context.Context, id uint32) (*keys.PreKey, error) {
  82. return nil, n.Error
  83. }
  84. func (n *NoopStore) RemovePreKey(ctx context.Context, id uint32) error {
  85. return n.Error
  86. }
  87. func (n *NoopStore) MarkPreKeysAsUploaded(ctx context.Context, upToID uint32) error {
  88. return n.Error
  89. }
  90. func (n *NoopStore) UploadedPreKeyCount(ctx context.Context) (int, error) {
  91. return 0, n.Error
  92. }
  93. func (n *NoopStore) PutSenderKey(ctx context.Context, group, user string, session []byte) error {
  94. return n.Error
  95. }
  96. func (n *NoopStore) GetSenderKey(ctx context.Context, group, user string) ([]byte, error) {
  97. return nil, n.Error
  98. }
  99. func (n *NoopStore) PutAppStateSyncKey(ctx context.Context, id []byte, key AppStateSyncKey) error {
  100. return n.Error
  101. }
  102. func (n *NoopStore) GetAppStateSyncKey(ctx context.Context, id []byte) (*AppStateSyncKey, error) {
  103. return nil, n.Error
  104. }
  105. func (n *NoopStore) GetLatestAppStateSyncKeyID(ctx context.Context) ([]byte, error) {
  106. return nil, n.Error
  107. }
  108. func (n *NoopStore) PutAppStateVersion(ctx context.Context, name string, version uint64, hash [128]byte) error {
  109. return n.Error
  110. }
  111. func (n *NoopStore) GetAppStateVersion(ctx context.Context, name string) (uint64, [128]byte, error) {
  112. return 0, [128]byte{}, n.Error
  113. }
  114. func (n *NoopStore) DeleteAppStateVersion(ctx context.Context, name string) error {
  115. return n.Error
  116. }
  117. func (n *NoopStore) PutAppStateMutationMACs(ctx context.Context, name string, version uint64, mutations []AppStateMutationMAC) error {
  118. return n.Error
  119. }
  120. func (n *NoopStore) DeleteAppStateMutationMACs(ctx context.Context, name string, indexMACs [][]byte) error {
  121. return n.Error
  122. }
  123. func (n *NoopStore) GetAppStateMutationMAC(ctx context.Context, name string, indexMAC []byte) (valueMAC []byte, err error) {
  124. return nil, n.Error
  125. }
  126. func (n *NoopStore) PutPushName(ctx context.Context, user types.JID, pushName string) (bool, string, error) {
  127. return false, "", n.Error
  128. }
  129. func (n *NoopStore) PutBusinessName(ctx context.Context, user types.JID, businessName string) (bool, string, error) {
  130. return false, "", n.Error
  131. }
  132. func (n *NoopStore) PutContactName(ctx context.Context, user types.JID, fullName, firstName string) error {
  133. return n.Error
  134. }
  135. func (n *NoopStore) PutAllContactNames(ctx context.Context, contacts []ContactEntry) error {
  136. return n.Error
  137. }
  138. func (n *NoopStore) PutManyRedactedPhones(ctx context.Context, entries []RedactedPhoneEntry) error {
  139. return n.Error
  140. }
  141. func (n *NoopStore) GetContact(ctx context.Context, user types.JID) (types.ContactInfo, error) {
  142. return types.ContactInfo{}, n.Error
  143. }
  144. func (n *NoopStore) GetAllContacts(ctx context.Context) (map[types.JID]types.ContactInfo, error) {
  145. return nil, n.Error
  146. }
  147. func (n *NoopStore) PutMutedUntil(ctx context.Context, chat types.JID, mutedUntil time.Time) error {
  148. return n.Error
  149. }
  150. func (n *NoopStore) PutPinned(ctx context.Context, chat types.JID, pinned bool) error {
  151. return n.Error
  152. }
  153. func (n *NoopStore) PutArchived(ctx context.Context, chat types.JID, archived bool) error {
  154. return n.Error
  155. }
  156. func (n *NoopStore) GetChatSettings(ctx context.Context, chat types.JID) (types.LocalChatSettings, error) {
  157. return types.LocalChatSettings{}, n.Error
  158. }
  159. func (n *NoopStore) PutMessageSecrets(ctx context.Context, inserts []MessageSecretInsert) error {
  160. return n.Error
  161. }
  162. func (n *NoopStore) PutMessageSecret(ctx context.Context, chat, sender types.JID, id types.MessageID, secret []byte) error {
  163. return n.Error
  164. }
  165. func (n *NoopStore) GetMessageSecret(ctx context.Context, chat, sender types.JID, id types.MessageID) ([]byte, types.JID, error) {
  166. return nil, types.EmptyJID, n.Error
  167. }
  168. func (n *NoopStore) PutPrivacyTokens(ctx context.Context, tokens ...PrivacyToken) error {
  169. return n.Error
  170. }
  171. func (n *NoopStore) GetPrivacyToken(ctx context.Context, user types.JID) (*PrivacyToken, error) {
  172. return nil, n.Error
  173. }
  174. func (n *NoopStore) PutDevice(ctx context.Context, store *Device) error {
  175. return n.Error
  176. }
  177. func (n *NoopStore) DeleteDevice(ctx context.Context, store *Device) error {
  178. return n.Error
  179. }
  180. func (n *NoopStore) GetBufferedEvent(ctx context.Context, ciphertextHash [32]byte) (*BufferedEvent, error) {
  181. return nil, nil
  182. }
  183. func (n *NoopStore) PutBufferedEvent(ctx context.Context, ciphertextHash [32]byte, plaintext []byte, serverTimestamp time.Time) error {
  184. return nil
  185. }
  186. func (n *NoopStore) DoDecryptionTxn(ctx context.Context, fn func(context.Context) error) error {
  187. return fn(ctx)
  188. }
  189. func (n *NoopStore) ClearBufferedEventPlaintext(ctx context.Context, ciphertextHash [32]byte) error {
  190. return nil
  191. }
  192. func (n *NoopStore) DeleteOldBufferedHashes(ctx context.Context) error {
  193. return nil
  194. }
  195. func (n *NoopStore) GetLIDForPN(ctx context.Context, pn types.JID) (types.JID, error) {
  196. return types.JID{}, n.Error
  197. }
  198. func (n *NoopStore) GetManyLIDsForPNs(ctx context.Context, pns []types.JID) (map[types.JID]types.JID, error) {
  199. return nil, n.Error
  200. }
  201. func (n *NoopStore) GetPNForLID(ctx context.Context, lid types.JID) (types.JID, error) {
  202. return types.JID{}, n.Error
  203. }
  204. func (n *NoopStore) PutManyLIDMappings(ctx context.Context, mappings []LIDMapping) error {
  205. return n.Error
  206. }
  207. func (n *NoopStore) PutLIDMapping(ctx context.Context, lid types.JID, jid types.JID) error {
  208. return n.Error
  209. }