Home | History | Annotate | Download | only in lowpan
      1 /*
      2  * Copyright (C) 2017 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 ANDROID_LOWPAN_CREDENTIAL_H
     18 #define ANDROID_LOWPAN_CREDENTIAL_H
     19 
     20 #include <binder/Parcelable.h>
     21 #include <utils/String16.h>
     22 #include <utils/StrongPointer.h>
     23 
     24 namespace android {
     25 
     26 namespace net {
     27 
     28 namespace lowpan {
     29 
     30 /*
     31  * C++ implementation of the Java class android.net.lowpan.LowpanCredential
     32  */
     33 class LowpanCredential : public Parcelable {
     34 public:
     35     static const int32_t UNSPECIFIED_MASTER_KEY_INDEX = 0;
     36     static const int MASTER_KEY_MAX_SIZE = 1048576;
     37 
     38     LowpanCredential();
     39     virtual ~LowpanCredential() = default;
     40     LowpanCredential(const LowpanCredential& x) = default;
     41 
     42     static status_t initMasterKey(LowpanCredential& out, const std::vector<uint8_t>& masterKey, int32_t masterKeyIndex);
     43     static status_t initMasterKey(LowpanCredential& out, const std::vector<uint8_t>& masterKey);
     44     static status_t initMasterKey(LowpanCredential& out, const uint8_t* masterKeyBytes, int masterKeyLen, int32_t masterKeyIndex);
     45     static status_t initMasterKey(LowpanCredential& out, const uint8_t* masterKeyBytes, int masterKeyLen);
     46 
     47     bool isMasterKey()const;
     48     bool getMasterKey(std::vector<uint8_t>* masterKey)const;
     49     bool getMasterKey(const uint8_t** masterKey, int* masterKeyLen)const;
     50     int32_t getMasterKeyIndex()const;
     51 
     52     bool operator==(const LowpanCredential& rhs);
     53     bool operator!=(const LowpanCredential& rhs) { return !(*this == rhs); }
     54 
     55 public:
     56     // Overrides
     57     status_t writeToParcel(Parcel* parcel) const override;
     58     status_t readFromParcel(const Parcel* parcel) override;
     59 
     60 private:
     61     // Data
     62     std::vector<uint8_t> mMasterKey;
     63     int32_t mMasterKeyIndex;
     64 };
     65 
     66 }  // namespace lowpan
     67 
     68 }  // namespace net
     69 
     70 }  // namespace android
     71 
     72 #endif  // ANDROID_LOWPAN_CREDENTIAL_H
     73