prashantpogde commented on a change in pull request #1182:
URL: https://github.com/apache/hadoop-ozone/pull/1182#discussion_r454204296



##########
File path: 
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/OzoneTokenIdentifier.java
##########
@@ -77,6 +80,122 @@ public Text getKind() {
     return KIND_NAME;
   }
 
+  /** Instead of relying on proto serialization, this
+   *  provides  explicit serialization for OzoneTokenIdentifier.
+   * @return byte[]
+   */
+  public byte[] toUniqueSerializedKey() {
+    ByteBuffer result =
+        ByteBuffer.allocate(4096);
+    result.order(ByteOrder.BIG_ENDIAN);
+    try {
+      result.putLong(getIssueDate());
+      result.putInt(getMasterKeyId());
+      result.putInt(getSequenceNumber());
+
+      result.putLong(getMaxDate());
+
+      result.putInt(getOwner().toString().length());
+      result.put(getOwner().toString().getBytes(StandardCharsets.UTF_8));
+
+      result.putInt(getRealUser().toString().length());
+      result.put(getRealUser().toString().getBytes(StandardCharsets.UTF_8));
+
+      result.putInt(getRenewer().toString().length());
+      result.put(getRenewer().toString().getBytes(StandardCharsets.UTF_8));
+
+      result.putInt(getTokenType().getNumber());
+      // Set s3 specific fields.
+      if (getTokenType().equals(S3AUTHINFO)) {
+        result.putInt(getAwsAccessId().length());
+        result.put(getAwsAccessId().getBytes(StandardCharsets.UTF_8));
+
+        result.putInt(getSignature().length());
+        result.put(getSignature().getBytes(StandardCharsets.UTF_8));
+
+        result.putInt(getStrToSign().length());
+        result.put(getStrToSign().getBytes(StandardCharsets.UTF_8));
+      } else {
+        result.putInt(getOmCertSerialId().length());
+        result.put(getOmCertSerialId().getBytes(StandardCharsets.UTF_8));
+        if (getOmServiceId() != null) {
+          result.putInt(getOmServiceId().length());
+          result.put(getOmServiceId().getBytes(StandardCharsets.UTF_8));
+        } else {
+          result.putInt(0);
+        }
+      }
+    } catch (IndexOutOfBoundsException e) {
+      throw new IllegalArgumentException(
+          "Can't encode the the raw data ", e);
+    }
+    return result.array();
+  }
+
+  /** Instead of relying on proto deserialization, this
+   *  provides  explicit deserialization for OzoneTokenIdentifier.
+   * @return byte[]
+   */
+  public static OzoneTokenIdentifier fromUniqueSerializedKey(byte[] rawData) {
+    OzoneTokenIdentifier result = newInstance();

Review comment:
       One failure in coverage check looks unreleted.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to