MCPcopy Create free account
hub / github.com/christophhart/HISE / encryptIntermediateFile

Method encryptIntermediateFile

hi_scripting/scripting/api/ScriptExpansion.cpp:1923–1998  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1921}
1922
1923bool ScriptEncryptedExpansion::encryptIntermediateFile(MainController* mc, const File& f, File expRoot)
1924{
1925 auto& h = mc->getExpansionHandler();
1926
1927 auto key = h.getEncryptionKey();
1928
1929 if (key.isEmpty())
1930 return h.setErrorMessage("Can't encode credentials without encryption key", true);
1931
1932#if HISE_USE_XML_FOR_HXI
1933 ScopedPointer<XmlElement> xml = XmlDocument::parse(f);
1934
1935 if (xml == nullptr)
1936 return h.setErrorMessage("Can't parse XML", true);
1937
1938 auto hxiData = ValueTree::fromXml(*xml);
1939#else
1940 FileInputStream fis(f);
1941 auto hxiData = ValueTree::readFromStream(fis);
1942#endif
1943
1944 if (hxiData.getType() != Identifier("Expansion"))
1945 return h.setErrorMessage("Invalid .hxi file", true);
1946
1947 if (expRoot == File())
1948 {
1949 auto hxiName = hxiData.getChildWithName(ExpansionIds::ExpansionInfo).getProperty(ExpansionIds::Name).toString();
1950
1951 if (hxiName.isEmpty())
1952 return h.setErrorMessage("Can't get expansion name", true);
1953
1954 expRoot = h.getExpansionFolder().getChildFile(hxiName);
1955 }
1956
1957 if (!expRoot.isDirectory())
1958 expRoot.createDirectory();
1959
1960 auto hash = (int64)hxiData.getChildWithName(ExpansionIds::ExpansionInfo)[ExpansionIds::Hash];
1961
1962 if (hash != key.hashCode64())
1963 return h.setErrorMessage("embedded key does not match encryption key", true);
1964
1965 auto obj = h.getCredentials();
1966
1967 if (!obj.isObject())
1968 return h.setErrorMessage("No credentials set for encryption", true);
1969
1970 auto c = ValueTreeConverters::convertDynamicObjectToBase64(var(obj), "Credentials", true);
1971 auto credentialsHash = c.hashCode64();
1972
1973 ValueTree credTree(ExpansionIds::Credentials);
1974
1975 MemoryBlock mb;
1976 mb.fromBase64Encoding(c);
1977
1978 if (ScopedPointer<BlowFish> bf = createBlowfish(mc))
1979 bf->encrypt(mb);
1980 else

Callers

nothing calls this directly

Calls 15

FileClass · 0.85
varFunction · 0.85
getChildWithNameMethod · 0.80
getExpansionFolderMethod · 0.80
getCredentialsMethod · 0.80
fromBase64EncodingMethod · 0.80
toBase64EncodingMethod · 0.80
parseFunction · 0.50
getEncryptionKeyMethod · 0.45
isEmptyMethod · 0.45
setErrorMessageMethod · 0.45

Tested by

no test coverage detected