1 /*
2 **
3 ** Copyright 2017, The Android Open Source Project
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 
18 #ifndef CONFIRMATIONUI_1_0_DEFAULT_PLATFORMSPECIFICS_H_
19 #define CONFIRMATIONUI_1_0_DEFAULT_PLATFORMSPECIFICS_H_
20 
21 #include <stdint.h>
22 #include <time.h>
23 
24 #include <android/hardware/confirmationui/1.0/IConfirmationResultCallback.h>
25 #include <android/hardware/confirmationui/1.0/generic/GenericOperation.h>
26 #include <android/hardware/confirmationui/support/confirmationui_utils.h>
27 
28 namespace android {
29 namespace hardware {
30 namespace confirmationui {
31 namespace V1_0 {
32 namespace implementation {
33 
34 struct MonotonicClockTimeStamper {
35     class TimeStamp {
36        public:
TimeStampMonotonicClockTimeStamper37         explicit TimeStamp(uint64_t ts) : timestamp_(ts), ok_(true) {}
TimeStampMonotonicClockTimeStamper38         TimeStamp() : timestamp_(0), ok_(false) {}
isOkMonotonicClockTimeStamper39         bool isOk() const { return ok_; }
uint64_tMonotonicClockTimeStamper40         operator const uint64_t() const { return timestamp_; }
41 
42        private:
43         uint64_t timestamp_;
44         bool ok_;
45     };
46     static TimeStamp now();
47 };
48 
49 class HMacImplementation {
50    public:
51     static support::NullOr<support::hmac_t> hmac256(
52         const support::auth_token_key_t& key,
53         std::initializer_list<support::ByteBufferProxy> buffers);
54 };
55 
56 class MyOperation : public generic::Operation<sp<IConfirmationResultCallback>,
57                                               MonotonicClockTimeStamper, HMacImplementation> {
58    public:
get()59     static MyOperation& get() {
60         static MyOperation op;
61         return op;
62     }
63 };
64 
65 }  // namespace implementation
66 }  // namespace V1_0
67 }  // namespace confirmationui
68 }  // namespace hardware
69 }  // namespace android
70 
71 #endif  // CONFIRMATIONUI_1_0_DEFAULT_PLATFORMSPECIFICS_H_
72