Commit 8e1cf1f
committed
api: centralize state check
We had two separate checks to decide if we will allow a protobuf
message API call to proceed: in hww.rs (forbid if initialized and
locked) and in api.rs in the can_call() function that defines which
states the API call can run in.
This makes it a bit hard to follow as split into two locations, and it
also prevents us from introducing a protobuf call that is only allowed
to run if the device is initialized but still locked. `Unlock` would
be such a useful new API call if we want to allow entering the
passphrase on the host.
The hww.rs check passed if `!initialized || !locked`,
which means the same as `uninitialized || seeded || unlocked`.
We change the `can_call` state checks to include this condition. For
this we split the local `Initialized` state into
`InitializedAndLocked` and `InitializedAndUnlocked`. For each line in
can_call, the two conditions are combined. The equivalent state check
in the end is simply to convert all `Initialized` checks to
`InitializedAndUnlocked`.
The `true` entries become explicit as they can't include
`InitializedAndLocked` (e.g. can't change the name using `DeviceName`
if initialized but not yet unlocked).1 parent 5fa56cc commit 8e1cf1f
2 files changed
+56
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | 122 | | |
129 | 123 | | |
130 | 124 | | |
| |||
417 | 411 | | |
418 | 412 | | |
419 | 413 | | |
420 | | - | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
421 | 422 | | |
422 | 423 | | |
423 | 424 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
99 | 101 | | |
100 | 102 | | |
101 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
102 | 108 | | |
103 | 109 | | |
104 | 110 | | |
| |||
108 | 114 | | |
109 | 115 | | |
110 | 116 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
118 | 145 | | |
119 | 146 | | |
120 | 147 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
125 | 152 | | |
126 | | - | |
| 153 | + | |
127 | 154 | | |
128 | 155 | | |
129 | 156 | | |
130 | 157 | | |
131 | 158 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
138 | 165 | | |
139 | 166 | | |
140 | 167 | | |
| |||
0 commit comments