Home | History | Annotate | Download | only in keymaster
      1 /*
      2  * Copyright 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef SYSTEM_KEYMASTER_OPERATION_H_
     18 #define SYSTEM_KEYMASTER_OPERATION_H_
     19 
     20 #include <assert.h>
     21 #include <stdint.h>
     22 #include <stdlib.h>
     23 
     24 #include <keymaster/google_keymaster_utils.h>
     25 #include <keymaster/keymaster_defs.h>
     26 #include <keymaster/logger.h>
     27 
     28 namespace keymaster {
     29 
     30 /**
     31  * Abstract base for all cryptographic operations.
     32  */
     33 class Operation {
     34   public:
     35     Operation(keymaster_purpose_t purpose, const Logger& logger)
     36         : purpose_(purpose), logger_(logger) {}
     37     virtual ~Operation() {}
     38 
     39     keymaster_purpose_t purpose() const { return purpose_; }
     40 
     41     const Logger& logger() { return logger_; }
     42 
     43     virtual keymaster_error_t Begin() = 0;
     44     virtual keymaster_error_t Update(const Buffer& input, Buffer* output) = 0;
     45     virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output) = 0;
     46     virtual keymaster_error_t Abort() = 0;
     47 
     48   private:
     49     const keymaster_purpose_t purpose_;
     50     const Logger& logger_;
     51 };
     52 
     53 }  // namespace keymaster
     54 
     55 #endif  // SYSTEM_KEYMASTER_OPERATION_H_
     56