| 1048 | } |
| 1049 | |
| 1050 | FSCryptContextRef FSCrypt::init_ctx(const std::vector<unsigned char>& fscrypt_auth) |
| 1051 | { |
| 1052 | if (fscrypt_auth.size() == 0) { |
| 1053 | return nullptr; |
| 1054 | } |
| 1055 | |
| 1056 | FSCryptContextRef ctx = std::make_shared<FSCryptContext>(cct); |
| 1057 | |
| 1058 | bufferlist bl; |
| 1059 | bl.append((const char *)fscrypt_auth.data(), fscrypt_auth.size()); |
| 1060 | |
| 1061 | auto bliter = bl.cbegin(); |
| 1062 | try { |
| 1063 | ctx->decode(bliter); |
| 1064 | } catch (buffer::error& err) { |
| 1065 | if (fscrypt_auth.size()) { |
| 1066 | ldout(cct, 0) << __func__ << " " << " failed to decode fscrypt_auth:" << fscrypt_hex_str(fscrypt_auth.data(), fscrypt_auth.size()) << dendl; |
| 1067 | } else { |
| 1068 | ldout(cct, 0) << __func__ << " " << " failed to decode fscrypt_auth: fscrypt_auth.size() == 0" << dendl; |
| 1069 | } |
| 1070 | return nullptr; |
| 1071 | } |
| 1072 | |
| 1073 | return ctx; |
| 1074 | } |
| 1075 | |
| 1076 | FSCryptDenc *FSCrypt::init_denc(const FSCryptContextRef& ctx, FSCryptKeyValidatorRef *kv, |
| 1077 | std::function<FSCryptDenc *()> gen_denc) |