PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/common/types/PolicyKeyHelpers.cpp

https://gitlab.com/admin-github-cloud/cynara
C++ | 64 lines | 34 code | 9 blank | 21 comment | 0 complexity | 8c41f68296c6f8c2ed5764a4e75b7ef1 MD5 | raw file
  1. /*
  2. * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
  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. * @file src/common/types/PolicyKeyHelpers.cpp
  18. * @author Aleksander Zdyb <a.zdyb@samsung.com>
  19. * @version 1.0
  20. * @brief Helper functions to manage Cynara::PolicyKey
  21. */
  22. #include <sstream>
  23. #include "PolicyKeyHelpers.h"
  24. namespace Cynara {
  25. std::string PolicyKeyHelpers::glueKey(const PolicyKey &key) {
  26. return glueKey(key.client(), key.user(), key.privilege());
  27. }
  28. std::string PolicyKeyHelpers::glueKey(const PolicyKeyFeature &client,
  29. const PolicyKeyFeature &user,
  30. const PolicyKeyFeature &privilege) {
  31. const std::string sep = ";";
  32. const std::string c = client.toString();
  33. const std::string u = user.toString();
  34. const std::string p = privilege.toString();
  35. std::ostringstream glued;
  36. glued << c << sep << u << sep << p << sep << c.size() << sep << u.size() << sep << p.size();
  37. return glued.str();
  38. };
  39. std::vector<std::string> PolicyKeyHelpers::keyVariants(const PolicyKey &key) {
  40. const auto &client = key.client();
  41. const auto &user = key.user();
  42. const auto &privilege = key.privilege();
  43. const auto w = PolicyKeyFeature::createWildcard();
  44. return {
  45. glueKey(client, user, privilege),
  46. glueKey(w, user, privilege),
  47. glueKey(client, w, privilege),
  48. glueKey(client, user, w),
  49. glueKey(w, w, privilege),
  50. glueKey(w, user, w),
  51. glueKey(client, w, w),
  52. glueKey(w, w, w),
  53. };
  54. }
  55. } /* namespace Cynara */