Class DiagnosisKey


  • @Entity
    public class DiagnosisKey
    extends Object
    A key generated for advertising over a window of time.
    • Field Detail

      • EXPECTED_ROLLING_PERIOD

        public static final int EXPECTED_ROLLING_PERIOD
        According to "Setting Up an Exposure Notification Server" by Apple, exposure notification servers are expected to reject any diagnosis keys that do not have a rolling period of a certain fixed value. See https://developer.apple.com/documentation/exposurenotification/setting_up_an_exposure_notification_server
        See Also:
        Constant Field Values
    • Constructor Detail

      • DiagnosisKey

        protected DiagnosisKey()
    • Method Detail

      • builder

        public static app.coronawarn.server.common.persistence.domain.DiagnosisKeyBuilders.Builder builder()
        Returns a DiagnosisKeyBuilder instance. A DiagnosisKey can then be build by either providing the required member values or by passing the respective protocol buffer object.
        Returns:
        DiagnosisKeyBuilder instance.
      • getKeyData

        public byte[] getKeyData()
        Returns the diagnosis key.
      • getRollingStartIntervalNumber

        public int getRollingStartIntervalNumber()
        Returns a number describing when a key starts. It is equal to startTimeOfKeySinceEpochInSecs / (60 * 10).
      • getRollingPeriod

        public int getRollingPeriod()
        Returns a number describing how long a key is valid. It is expressed in increments of 10 minutes (e.g. 144 for 24 hours).
      • getTransmissionRiskLevel

        public int getTransmissionRiskLevel()
        Returns the risk of transmission associated with the person this key came from.
      • getSubmissionTimestamp

        public long getSubmissionTimestamp()
        Returns the timestamp associated with the submission of this DiagnosisKey as hours since epoch.
      • isYoungerThanRetentionThreshold

        public boolean isYoungerThanRetentionThreshold​(int daysToRetain)
        Checks if this diagnosis key falls into the period between now, and the retention threshold.
        Parameters:
        daysToRetain - the number of days before a key is outdated
        Returns:
        true, if the rolling start interval number is within the time between now, and the given days to retain
        Throws:
        IllegalArgumentException - if daysToRetain is negative.
      • validate

        public Set<javax.validation.ConstraintViolation<DiagnosisKey>> validate()
        Gets any constraint violations that this key might incorporate.

        • Risk level must be between 0 and 8
        • Rolling start interval number must be greater than 0
        • Rolling start number cannot be in the future
        • Rolling period must be positive number
        • Key data must be byte array of length 16
        Returns:
        A set of constraint violations of this key.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object