1 /* 2 * Copyright (C) 2014 The Android Open Source Project 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 package libcore.tlswire.handshake; 17 /** 18 * {@code CompressionMethod} enum from TLS 1.2 RFC 5246. 19 */ 20 public class CompressionMethod { 21 public static final CompressionMethod NULL = new CompressionMethod(0, "null"); 22 public static final CompressionMethod DEFLATE = new CompressionMethod(1, "deflate"); 23 public final int type; 24 public final String name; 25 private CompressionMethod(int type, String name) { 26 this.type = type; 27 this.name = name; 28 } 29 public static CompressionMethod valueOf(int type) { 30 switch (type) { 31 case 0: 32 return NULL; 33 case 1: 34 return DEFLATE; 35 default: 36 return new CompressionMethod(type, String.valueOf(type)); 37 } 38 } 39 @Override 40 public String toString() { 41 return name; 42 } 43 @Override 44 public int hashCode() { 45 final int prime = 31; 46 int result = 1; 47 result = prime * result + type; 48 return result; 49 } 50 @Override 51 public boolean equals(Object obj) { 52 if (this == obj) { 53 return true; 54 } 55 if (obj == null) { 56 return false; 57 } 58 if (getClass() != obj.getClass()) { 59 return false; 60 } 61 CompressionMethod other = (CompressionMethod) obj; 62 if (type != other.type) { 63 return false; 64 } 65 return true; 66 } 67 } 68