Skip to content

Commit ae5c492

Browse files
committed
store: add noop store that always returns an error
1 parent af3dc03 commit ae5c492

File tree

4 files changed

+232
-9
lines changed

4 files changed

+232
-9
lines changed

store/clientpayload.go

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"go.mau.fi/whatsmeow/proto/waCompanionReg"
2121
"go.mau.fi/whatsmeow/proto/waWa6"
22+
"go.mau.fi/whatsmeow/types"
2223
)
2324

2425
// WAVersionContainer is a container for a WhatsApp web version number.
@@ -174,6 +175,9 @@ func (device *Device) getLoginPayload() *waWa6.ClientPayload {
174175

175176
func (device *Device) GetClientPayload() *waWa6.ClientPayload {
176177
if device.ID != nil {
178+
if *device.ID == types.EmptyJID {
179+
panic(fmt.Errorf("GetClientPayload called with empty JID"))
180+
}
177181
return device.getLoginPayload()
178182
} else {
179183
return device.getRegistrationPayload()

store/noop.go

+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
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+
7+
package store
8+
9+
import (
10+
"errors"
11+
"time"
12+
13+
"go.mau.fi/whatsmeow/types"
14+
"go.mau.fi/whatsmeow/util/keys"
15+
)
16+
17+
type NoopStore struct {
18+
Error error
19+
}
20+
21+
var nilStore = &NoopStore{Error: errors.New("store is nil")}
22+
var nilKey = &keys.KeyPair{Priv: &[32]byte{}, Pub: &[32]byte{}}
23+
var NoopDevice = &Device{
24+
ID: &types.EmptyJID,
25+
NoiseKey: nilKey,
26+
IdentityKey: nilKey,
27+
28+
Identities: nilStore,
29+
Sessions: nilStore,
30+
PreKeys: nilStore,
31+
SenderKeys: nilStore,
32+
AppStateKeys: nilStore,
33+
AppState: nilStore,
34+
Contacts: nilStore,
35+
ChatSettings: nilStore,
36+
MsgSecrets: nilStore,
37+
PrivacyTokens: nilStore,
38+
Container: nilStore,
39+
}
40+
41+
var _ AllStores = (*NoopStore)(nil)
42+
var _ DeviceContainer = (*NoopStore)(nil)
43+
44+
func (n *NoopStore) PutIdentity(address string, key [32]byte) error {
45+
return n.Error
46+
}
47+
48+
func (n *NoopStore) DeleteAllIdentities(phone string) error {
49+
return n.Error
50+
}
51+
52+
func (n *NoopStore) DeleteIdentity(address string) error {
53+
return n.Error
54+
}
55+
56+
func (n *NoopStore) IsTrustedIdentity(address string, key [32]byte) (bool, error) {
57+
return false, n.Error
58+
}
59+
60+
func (n *NoopStore) GetSession(address string) ([]byte, error) {
61+
return nil, n.Error
62+
}
63+
64+
func (n *NoopStore) HasSession(address string) (bool, error) {
65+
return false, n.Error
66+
}
67+
68+
func (n *NoopStore) PutSession(address string, session []byte) error {
69+
return n.Error
70+
}
71+
72+
func (n *NoopStore) DeleteAllSessions(phone string) error {
73+
return n.Error
74+
}
75+
76+
func (n *NoopStore) DeleteSession(address string) error {
77+
return n.Error
78+
}
79+
80+
func (n *NoopStore) GetOrGenPreKeys(count uint32) ([]*keys.PreKey, error) {
81+
return nil, n.Error
82+
}
83+
84+
func (n *NoopStore) GenOnePreKey() (*keys.PreKey, error) {
85+
return nil, n.Error
86+
}
87+
88+
func (n *NoopStore) GetPreKey(id uint32) (*keys.PreKey, error) {
89+
return nil, n.Error
90+
}
91+
92+
func (n *NoopStore) RemovePreKey(id uint32) error {
93+
return n.Error
94+
}
95+
96+
func (n *NoopStore) MarkPreKeysAsUploaded(upToID uint32) error {
97+
return n.Error
98+
}
99+
100+
func (n *NoopStore) UploadedPreKeyCount() (int, error) {
101+
return 0, n.Error
102+
}
103+
104+
func (n *NoopStore) PutSenderKey(group, user string, session []byte) error {
105+
return n.Error
106+
}
107+
108+
func (n *NoopStore) GetSenderKey(group, user string) ([]byte, error) {
109+
return nil, n.Error
110+
}
111+
112+
func (n *NoopStore) PutAppStateSyncKey(id []byte, key AppStateSyncKey) error {
113+
return n.Error
114+
}
115+
116+
func (n *NoopStore) GetAppStateSyncKey(id []byte) (*AppStateSyncKey, error) {
117+
return nil, n.Error
118+
}
119+
120+
func (n *NoopStore) GetLatestAppStateSyncKeyID() ([]byte, error) {
121+
return nil, n.Error
122+
}
123+
124+
func (n *NoopStore) PutAppStateVersion(name string, version uint64, hash [128]byte) error {
125+
return n.Error
126+
}
127+
128+
func (n *NoopStore) GetAppStateVersion(name string) (uint64, [128]byte, error) {
129+
return 0, [128]byte{}, n.Error
130+
}
131+
132+
func (n *NoopStore) DeleteAppStateVersion(name string) error {
133+
return n.Error
134+
}
135+
136+
func (n *NoopStore) PutAppStateMutationMACs(name string, version uint64, mutations []AppStateMutationMAC) error {
137+
return n.Error
138+
}
139+
140+
func (n *NoopStore) DeleteAppStateMutationMACs(name string, indexMACs [][]byte) error {
141+
return n.Error
142+
}
143+
144+
func (n *NoopStore) GetAppStateMutationMAC(name string, indexMAC []byte) (valueMAC []byte, err error) {
145+
return nil, n.Error
146+
}
147+
148+
func (n *NoopStore) PutPushName(user types.JID, pushName string) (bool, string, error) {
149+
return false, "", n.Error
150+
}
151+
152+
func (n *NoopStore) PutBusinessName(user types.JID, businessName string) (bool, string, error) {
153+
return false, "", n.Error
154+
}
155+
156+
func (n *NoopStore) PutContactName(user types.JID, fullName, firstName string) error {
157+
return n.Error
158+
}
159+
160+
func (n *NoopStore) PutAllContactNames(contacts []ContactEntry) error {
161+
return n.Error
162+
}
163+
164+
func (n *NoopStore) GetContact(user types.JID) (types.ContactInfo, error) {
165+
return types.ContactInfo{}, n.Error
166+
}
167+
168+
func (n *NoopStore) GetAllContacts() (map[types.JID]types.ContactInfo, error) {
169+
return nil, n.Error
170+
}
171+
172+
func (n *NoopStore) PutMutedUntil(chat types.JID, mutedUntil time.Time) error {
173+
return n.Error
174+
}
175+
176+
func (n *NoopStore) PutPinned(chat types.JID, pinned bool) error {
177+
return n.Error
178+
}
179+
180+
func (n *NoopStore) PutArchived(chat types.JID, archived bool) error {
181+
return n.Error
182+
}
183+
184+
func (n *NoopStore) GetChatSettings(chat types.JID) (types.LocalChatSettings, error) {
185+
return types.LocalChatSettings{}, n.Error
186+
}
187+
188+
func (n *NoopStore) PutMessageSecrets(inserts []MessageSecretInsert) error {
189+
return n.Error
190+
}
191+
192+
func (n *NoopStore) PutMessageSecret(chat, sender types.JID, id types.MessageID, secret []byte) error {
193+
return n.Error
194+
}
195+
196+
func (n *NoopStore) GetMessageSecret(chat, sender types.JID, id types.MessageID) ([]byte, error) {
197+
return nil, n.Error
198+
}
199+
200+
func (n *NoopStore) PutPrivacyTokens(tokens ...PrivacyToken) error {
201+
return n.Error
202+
}
203+
204+
func (n *NoopStore) GetPrivacyToken(user types.JID) (*PrivacyToken, error) {
205+
return nil, n.Error
206+
}
207+
208+
func (n *NoopStore) PutDevice(store *Device) error {
209+
return n.Error
210+
}
211+
212+
func (n *NoopStore) DeleteDevice(store *Device) error {
213+
return n.Error
214+
}

store/sqlstore/store.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,7 @@ func NewSQLStore(c *Container, jid types.JID) *SQLStore {
5757
}
5858
}
5959

60-
var (
61-
_ store.IdentityStore = (*SQLStore)(nil)
62-
_ store.SessionStore = (*SQLStore)(nil)
63-
_ store.PreKeyStore = (*SQLStore)(nil)
64-
_ store.SenderKeyStore = (*SQLStore)(nil)
65-
_ store.AppStateSyncKeyStore = (*SQLStore)(nil)
66-
_ store.AppStateStore = (*SQLStore)(nil)
67-
_ store.ContactStore = (*SQLStore)(nil)
68-
)
60+
var _ store.AllStores = (*SQLStore)(nil)
6961

7062
const (
7163
putIdentityQuery = `

store/store.go

+13
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ type PrivacyTokenStore interface {
126126
GetPrivacyToken(user types.JID) (*PrivacyToken, error)
127127
}
128128

129+
type AllStores interface {
130+
IdentityStore
131+
SessionStore
132+
PreKeyStore
133+
SenderKeyStore
134+
AppStateSyncKeyStore
135+
AppStateStore
136+
ContactStore
137+
ChatSettingsStore
138+
MsgSecretStore
139+
PrivacyTokenStore
140+
}
141+
129142
type Device struct {
130143
Log waLog.Logger
131144

0 commit comments

Comments
 (0)