Add type parameter to "get" commands
[platform/core/security/key-manager.git] / src / manager / crypto / tz-backend / tz-context.cpp
index 2c013ae..8710982 100644 (file)
@@ -746,7 +746,8 @@ RawBuffer TrustZoneContext::exportWrappedKey(const RawBuffer &wrappingKeyId,
                                                                                         const uint32_t ctrLenOrTagSizeBits,
                                                                                         const RawBuffer &aad,
                                                                                         const RawBuffer &keyToWrapId,
-                                                                                        const Pwd &keyToWrapPwd)
+                                                                                        const Pwd &keyToWrapPwd,
+                                                                                        tz_data_type keyToWrapType)
 {
        // command ID = CMD_EXPORT_WRAPPED_KEY
        LogDebug("TrustZoneContext::exportWrappedKey");
@@ -758,19 +759,20 @@ RawBuffer TrustZoneContext::exportWrappedKey(const RawBuffer &wrappingKeyId,
                                                          ctrLenOrTagSizeBits,
                                                          aad,
                                                          keyToWrapId,
-                                                         keyToWrapPwd);
+                                                         keyToWrapPwd,
+                                                         keyToWrapType);
 
        TrustZoneMemory inMemory(m_Context, sIn.GetSize(), TEEC_MEM_INPUT);
        sIn.Serialize(inMemory);
 
-       uint32_t data_size = 0;
-       GetDataSize(keyToWrapId, data_size);
+       uint32_t dataSize = 0;
+       GetDataSize(keyToWrapId, keyToWrapType, dataSize);
 
-       LogDebug("GetData data_size = [" << data_size << "]");
+       LogDebug("GetData data_size = [" << dataSize << "]");
 
        // encrypted data may be longer
        TZSerializer sOut;
-       sOut.Push(new TZSerializableBinary(data_size + KM_ENCRYPTION_OVERHEAD));
+       sOut.Push(new TZSerializableBinary(dataSize + KM_ENCRYPTION_OVERHEAD));
        TrustZoneMemory outMemory(m_Context, sOut.GetSize(), TEEC_MEM_OUTPUT);
        sOut.Serialize(outMemory);
 
@@ -786,12 +788,14 @@ RawBuffer TrustZoneContext::exportWrappedKey(const RawBuffer &wrappingKeyId,
        return wrappedKey;
 }
 
-void TrustZoneContext::GetDataSize(const RawBuffer &dataId, uint32_t &dataSize)
+void TrustZoneContext::GetDataSize(const RawBuffer &dataId,
+                                                                  const tz_data_type type,
+                                                                  uint32_t &dataSize)
 {
        // command ID = CMD_GET_DATA_SIZE
        LogDebug("Object ID (passed to CMD_GET_DATA_SIZE) is (hex): " << rawToHexString(dataId));
 
-       auto sIn = makeSerializer(dataId);
+       auto sIn = makeSerializer(dataId, type);
        TrustZoneMemory inMemory(m_Context, sIn.GetSize(), TEEC_MEM_INPUT);
        sIn.Serialize(inMemory);
 
@@ -803,17 +807,18 @@ void TrustZoneContext::GetDataSize(const RawBuffer &dataId, uint32_t &dataSize)
 
 void TrustZoneContext::getData(const RawBuffer &dataId,
                         const Pwd &pwd,
+                        const tz_data_type type,
                         RawBuffer &data)
 {
        // command ID = CMD_GET_DATA
        LogDebug("Object ID (passed to CMD_GET_DATA) is (hex): " << rawToHexString(dataId));
 
-       auto sIn = makeSerializer(dataId, pwd);
+       auto sIn = makeSerializer(dataId, pwd, type);
        TrustZoneMemory inMemory(m_Context, sIn.GetSize(), TEEC_MEM_INPUT);
        sIn.Serialize(inMemory);
 
        uint32_t data_size = 0;
-       GetDataSize(dataId, data_size);
+       GetDataSize(dataId, type, data_size);
 
        LogDebug("GetData data_size = [" << data_size << "]");