Capability.cpp 973 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2024-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #include "Capability.hpp"
  14. namespace ZeroTier {
  15. bool Capability::sign(const Identity &from,const Address &to)
  16. {
  17. try {
  18. for(unsigned int i=0;((i<_maxCustodyChainLength)&&(i<ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH));++i) {
  19. if (!(_custody[i].to)) {
  20. Buffer<(sizeof(Capability) * 2)> tmp;
  21. this->serialize(tmp,true);
  22. _custody[i].to = to;
  23. _custody[i].from = from.address();
  24. _custody[i].signatureLength = from.sign(tmp.data(),tmp.size(),_custody[i].signature,sizeof(_custody[i].signature));
  25. return true;
  26. }
  27. }
  28. } catch ( ... ) {}
  29. return false;
  30. }
  31. } // namespace ZeroTier