1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.ssl;
17
18 import io.netty.buffer.ByteBuf;
19 import io.netty.buffer.ByteBufAllocator;
20 import io.netty.util.AbstractReferenceCounted;
21 import io.netty.util.IllegalReferenceCountException;
22 import io.netty.util.internal.ObjectUtil;
23
24
25
26
27
28
29
30
31 class PemValue extends AbstractReferenceCounted implements PemEncoded {
32
33 private final ByteBuf content;
34
35 private final boolean sensitive;
36
37 public PemValue(ByteBuf content, boolean sensitive) {
38 this.content = ObjectUtil.checkNotNull(content, "content");
39 this.sensitive = sensitive;
40 }
41
42 @Override
43 public boolean isSensitive() {
44 return sensitive;
45 }
46
47 @Override
48 public ByteBuf content() {
49 int count = refCnt();
50 if (count <= 0) {
51 throw new IllegalReferenceCountException(count);
52 }
53
54 return content;
55 }
56
57 @Override
58 public PemValue copy() {
59 return new PemValue(content.copy(), sensitive);
60 }
61
62 @Override
63 public PemValue duplicate() {
64 return new PemValue(content.duplicate(), sensitive);
65 }
66
67 @Override
68 public PemValue retain() {
69 return (PemValue) super.retain();
70 }
71
72 @Override
73 public PemValue retain(int increment) {
74 return (PemValue) super.retain(increment);
75 }
76
77 @Override
78 protected void deallocate() {
79 if (sensitive) {
80 SslUtils.zeroout(content);
81 }
82 content.release();
83 }
84 }