2020-10-22 15:40:55 +00:00
|
|
|
package container
|
|
|
|
|
2020-10-22 16:10:42 +00:00
|
|
|
// SysAttributePrefix is a prefix of key to system attribute.
|
2023-03-15 09:50:43 +00:00
|
|
|
const SysAttributePrefix = "__SYSTEM__"
|
2020-10-22 15:40:55 +00:00
|
|
|
|
|
|
|
const (
|
2021-10-11 08:04:58 +00:00
|
|
|
// SysAttributeName is a string of human-friendly container name registered as the domain in NNS contract.
|
|
|
|
SysAttributeName = SysAttributePrefix + "NAME"
|
|
|
|
|
|
|
|
// SysAttributeZone is a string of zone for container name.
|
|
|
|
SysAttributeZone = SysAttributePrefix + "ZONE"
|
2022-05-04 17:11:22 +00:00
|
|
|
|
|
|
|
// SysAttributeHomomorphicHashing is a container's homomorphic hashing state.
|
|
|
|
SysAttributeHomomorphicHashing = SysAttributePrefix + "DISABLE_HOMOMORPHIC_HASHING"
|
2020-10-22 15:40:55 +00:00
|
|
|
)
|
2021-10-14 08:50:05 +00:00
|
|
|
|
2023-03-06 12:24:58 +00:00
|
|
|
// SysAttributePrefixNeoFS is a prefix of key to system attribute.
|
2023-05-03 10:46:07 +00:00
|
|
|
// Deprecated: use SysAttributePrefix.
|
2023-03-06 12:24:58 +00:00
|
|
|
const SysAttributePrefixNeoFS = "__NEOFS__"
|
|
|
|
|
|
|
|
const (
|
|
|
|
// SysAttributeNameNeoFS is a string of human-friendly container name registered as the domain in NNS contract.
|
2023-05-03 10:46:07 +00:00
|
|
|
// Deprecated: use SysAttributeName.
|
2023-03-06 12:24:58 +00:00
|
|
|
SysAttributeNameNeoFS = SysAttributePrefixNeoFS + "NAME"
|
|
|
|
|
|
|
|
// SysAttributeZoneNeoFS is a string of zone for container name.
|
2023-05-03 10:46:07 +00:00
|
|
|
// Deprecated: use SysAttributeZone.
|
2023-03-06 12:24:58 +00:00
|
|
|
SysAttributeZoneNeoFS = SysAttributePrefixNeoFS + "ZONE"
|
|
|
|
|
|
|
|
// SysAttributeHomomorphicHashingNeoFS is a container's homomorphic hashing state.
|
2023-05-03 10:46:07 +00:00
|
|
|
// Deprecated: use SysAttributeHomomorphicHashing.
|
2023-03-06 12:24:58 +00:00
|
|
|
SysAttributeHomomorphicHashingNeoFS = SysAttributePrefixNeoFS + "DISABLE_HOMOMORPHIC_HASHING"
|
|
|
|
)
|
|
|
|
|
2021-10-14 08:50:05 +00:00
|
|
|
// SysAttributeZoneDefault is a default value for SysAttributeZone attribute.
|
|
|
|
const SysAttributeZoneDefault = "container"
|
2022-05-04 17:11:22 +00:00
|
|
|
|
|
|
|
const disabledHomomorphicHashingValue = "true"
|
|
|
|
|
|
|
|
// HomomorphicHashingState returns container's homomorphic
|
|
|
|
// hashing state:
|
2022-09-15 05:20:13 +00:00
|
|
|
// - true if hashing is enabled;
|
|
|
|
// - false if hashing is disabled.
|
2022-05-04 17:11:22 +00:00
|
|
|
//
|
|
|
|
// All container's attributes must be unique, otherwise behavior
|
|
|
|
// is undefined.
|
|
|
|
//
|
|
|
|
// See also SetHomomorphicHashingState.
|
|
|
|
func (c Container) HomomorphicHashingState() bool {
|
|
|
|
for i := range c.attr {
|
2023-03-06 12:24:58 +00:00
|
|
|
if c.attr[i].GetKey() == SysAttributeHomomorphicHashing || c.attr[i].GetKey() == SysAttributeHomomorphicHashingNeoFS {
|
2022-05-04 17:11:22 +00:00
|
|
|
return c.attr[i].GetValue() != disabledHomomorphicHashingValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetHomomorphicHashingState sets homomorphic hashing state for
|
|
|
|
// container.
|
|
|
|
//
|
|
|
|
// All container's attributes must be unique, otherwise behavior
|
|
|
|
// is undefined.
|
|
|
|
//
|
|
|
|
// See also HomomorphicHashingState.
|
|
|
|
func (c *Container) SetHomomorphicHashingState(enable bool) {
|
|
|
|
for i := range c.attr {
|
2023-03-06 12:24:58 +00:00
|
|
|
if c.attr[i].GetKey() == SysAttributeHomomorphicHashing || c.attr[i].GetKey() == SysAttributeHomomorphicHashingNeoFS {
|
2022-05-04 17:11:22 +00:00
|
|
|
if enable {
|
|
|
|
// approach without allocation/waste
|
|
|
|
// coping works since the attributes
|
|
|
|
// order is not important
|
|
|
|
c.attr[i] = c.attr[len(c.attr)-1]
|
|
|
|
c.attr = c.attr[:len(c.attr)-1]
|
|
|
|
} else {
|
|
|
|
c.attr[i].SetValue(disabledHomomorphicHashingValue)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !enable {
|
|
|
|
attr := Attribute{}
|
|
|
|
attr.SetKey(SysAttributeHomomorphicHashing)
|
|
|
|
attr.SetValue(disabledHomomorphicHashingValue)
|
|
|
|
|
|
|
|
c.attr = append(c.attr, attr)
|
|
|
|
}
|
|
|
|
}
|